I guess I should start first by explaining what the system actually does to get a better understanding.
The system is a payslip viewer website wherein the uploader(hr personnel) uploads a bunch of payslips in excel format and those entries get saved into the database. The payslip viewer then fetches the emp_id
of the currently logged in user and displays all their earnings, deductions, info
AND their total earnings(all earnings are added), total deductions(all deductions are added) and netpay(total earning-total deduction)
.
My problem is that my professor said I need to "normalize" the table but I was left wondering how could I possibly normalize this as I think this is as "normalized" as it gets. However, I did try to create two erds but I have a couple of questions:
My first ERD:
My second ERD:
(I did this to try and normalize it but for the system's requirement, I don't think this is appropriate)
My guess is that your prof wants you to not have 30 deduction fields. Like... when you set up a table and find yourself doing:
object_typa_1 | object_typa_2 | object_typa_3 | object_typa_4 | object_typeb_1 | object_typeb_2 ..
And storing the values in their respective fields. Instead, you should normalize that in case some day you have to add deduction31
you don't have to do an ALTER TABLE and schluff around all your SQL to accomodate.
Instead:
Object Table:
type | number | value
In your case:
employees:
emp_id | password | name | ...
payslips:
id | emp_id | other payslip attributes | ...
payslip_items:
payslip_id | type | number | value
In the payslip_items table you stick in multiple records for each payslip. You tell it whether that item was an earning or a deduction in the type
field. You say which earning or deduction it was in that number
field... probably not the best name, but good for example. And then the value of that earning/deduction in the value
field. So in reality your payslip_items table will be 34 records (30 deductions and 4 earnings) for each payslip...
The reason you want to do it this way is that in the real world, as soon as you launch this thing for the client/business partner, they will want to add a new deduction or earning to the payslip (GUARANTEED). This schema works because you don't have to ALTER TABLE and mess with ALL of your sql that deals with payslip_items. It will grow and shrink as you need.