Normalization (mysql)
Normalization (mysql)
Normalization
First normal form (1NF) lays the groundwork for an organized database design:
1. Ensure that each table has a primary key: minimal set of attributes which can
uniquely identify a record.
2. Eliminate repeating groups (categories of data which would seem to be required
a different number of times on different records) by defining keyed and non-
keyed attributes appropriately.
3. Atomicity: Each attribute must contain a single value, not a set of values.
Second normal form (2NF) If a table has a composite key, all attributes must be
related to the whole key:
1. The database must meet all the requirements of the first normal form.
2. Data which is redundantly duplicated across multiple rows of a table is moved
out to a separate table.
Third normal form (3NF) requires that data stored in a table be dependent only on
the primary key, and not on any other field in the table:
1. The database must meet all the requirements of the second normal form.
2. Any field which is dependent not only on the primary key but also on another
field is moved out to a separate table.
1.1.2. Normalization Process
The figure below illustrates how original form (or data model) go through the
normalization process such as 1NF, 2NF and 3NF:
Eliminate
repeating
groups
1NF
Functional
Primary Key Move out to
Dependence
separate table
2NF
Functional
Primary Dependence Move out to
Key separate table
3NF
Table below is a sample original form for sales orders that is to go through the
normalization process. An attribute with underline represents the primary key of the form.
Table 1 - Sample original form
Order Order Date Customer Customer Customer Product ID Product ID Product ID
Number ID Name Address Product Product Product
Quantity Quantity Quantity
Unit Price Unit Price Unit Price
1 10/01/2007 1 ABC Yangon A01 B99 C01
Pencil Notebook Eraser S
5 1 3
20 95 50
2 31/01/2007 2 XYZ Bagan C01 C02 C03
Eraser S Eraser M Eraser L
1 1 1
50 60 80
3 31/01/2007 1 ABC Yangon A01
Pencil
1
20
Table 2 - 1NF
Order Order Date Customer Customer Customer Product Product Quantity Unit
Number ID Name Address ID Price
1 10/01/2007 1 ABC Yangon A01 Pencil 5 20
1 10/01/2007 1 ABC Yangon B99 Notebook 1 95
1 10/01/2007 1 ABC Yangon C01 Eraser S 3 50
2 31/01/2007 2 XYZ Bagan C01 Eraser S 1 50
2 31/01/2007 2 XYZ Bagan C02 Eraser M 1 60
2 31/01/2007 2 XYZ Bagan C03 Eraser L 1 80
3 31/01/2007 1 ABC Yangon A01 Pencil 1 20
(2) Second Normal Form (2NF)
Remove functional dependences for the primary key (Order Number and Product ID)
attributes to separate tables such as Order, Order Details and Product tables as shown in
Table below:
Table 3 - 2NF
Order
Order Order Date Customer Customer Customer
Number ID Name Address
1 10/01/2007 1 ABC Yangon
2 10/01/2007 2 XYZ Bagan
1 A01 5 20
1 B99 1 95
1 C01 3 50
2 C01 1 50
2 C02 1 60
2 C03 1 80
3 A01 1 20
Order Details
Order Product ID Quantity
Number
1 A01 5
1 B99 1
1 C01 3
2 C01 1
2 C02 1
2 C03 1
3 A01 1
Product
Product Product Unit Price
ID
A01 Pencil 20
B99 Note 95
C01 Eraser S 50
C02 Eraser M 60
C03 Eraser L 80
(3) Third Normal Form (3NF)
Remove functional dependences for non-primary key (Order Number and Product ID)
attributes to separate tables such as Customer as shown in Table below:
Table 4 - 3NF
Order
Order Order Customer
Number Date ID
1 10/01/2007 1
2 10/01/2007 2
Order Details
Order Product ID Quantity
Number
1 A01 5
1 B99 1
1 C01 3
2 C01 1
2 C02 1
2 C03 1
3 A01 1
Product
Product Product Unit Price
ID
A01 Pencil 20
B99 Note 95
C01 Eraser S 50
C02 Eraser M 60
C03 Eraser L 80
Customer
Customer Customer Customer
ID Name Address
1 ABC Yangon
2 XYZ Bagan
1.1.3. Normalization and Database Design
Relational database model based on the normalization process will be described as
shown in Figure below:
Primary Key:
Foreign Key: