SQL Strategy - A site to master SQL while executing it on the Web
Home >> Normalization strategy - From first normal form to second normal form

From first normal form to second normal form

Let's eliminate the partial function dependence and go to the second normal form.

table of the first normalized form

voucherNodateCustomer CodeCustomer NameAddressCity CodePhoneNo
01292004/08/10001hoo Commercial companyYokohama012045****
01572004/08/13103Boo Real EstateKawasaki033044****
02482004/08/22056foo IndustryFujisawa056047****

voucherNogoodscodeunitquantityunit price
0129Z101cm200
1000
0129N029gallon50
3000
0157K403kg402000
0248N029gallon3001000
0248T110dl1209400
0248Q200l870750

Although the first normalized form removes the limit on the number of sales at a time, this still results in wasted space. For example, if a hoo Commercial company purchases 3 days in a row, there will be duplicates in one table, even though the Customer Code, Customer Name, and Address are the same data. The same is true if there are hit GOODS and a large number of the same GOODS are purchased. Such a situation is wasteful and should be eliminated, no matter how large the disk capacity has become. Furthermore, the update process is wasteful because it requires updating data in multiple locations.

So let's take another step from first normal form to second normal form.

The Customer Code is different for each customer, so you know the Customer Name and Address from the Customer Code. In other words, they are function dependent. Among function dependencies, those that are function dependent on items other than the primary key are called partial function dependencies.

Eliminating this partial function dependence of Table in the first normal form yields the second normal form. The elimination of partial function dependencies is done by splitting the table. In the same way, unit and unit price, which are partially dependent on goodscode, are also divided, resulting in the following table structure.

Tables in second normal form Orders table

voucherNodateCustomer Code
01292004/08/10001
01572004/08/13103
02482004/08/22056

customer table
Customer CodeCustomer NameAddressCity CodePhoneNo
001hoo Commercial companyYokohama012045****
103Boo Real EstateKawasaki033044****
056foo IndustryFujisawa056047****

quantity table
voucherNogoodscodequantity
0129Z101200
0129N02950
0157K40340
0248N029300
0248T110120
0248Q200870

GOODS TABLE
goodscodeunitunit price
Z101cm1000
N029gallon3000
K403kg2000
T110dl9400
Q200l750

This saves disk space. The update can be localized (e.g., only one record is needed to update the unit price of N029). (For example, updating the unit price of N029 requires only one record.) The key entry in each table is the one to which the function is subordinated.