Differences Between Normal Forms
Understanding Normal Forms
- First Normal Form (1NF): Ensures that all data is atomic and that each table has a unique identifier.
- Second Normal Form (2NF): Eliminates partial-key dependencies by ensuring that all non-key attributes depend on the entire primary key.
- Third Normal Form (3NF): Removes transitive dependencies, ensuring that non-key attributes depend only on the primary key.
First Normal Form (1NF)
- Repeating data is moved into a new entity.
- Non-repeating data remains in its own entity and is given a primary key.
- The primary key of the non-repeating entity is added to the new entity as a foreign key.
- The new entity is assigned a unique identifier, usually a composite key.
- A common issue at this stage is partial key dependencies, where some attributes depend on only part of the composite key.
- Partial dependencies violate normalisation rules.
Second Normal Form (2NF)
- Partial key dependencies are moved into their own entity.
- A new primary key is assigned to that entity.
- The original entity keeps the removed data’s key as both a primary and foreign key.
- The problem that remains is the presence of non-key (transitive) dependencies, attributes that do not rely on the key at all.
- These still violate the normalisation principle.
Third Normal Form (3NF)
- Transitive or non-key dependencies are moved into separate entities.
- Each new entity is given its own primary key.
- The new primary key becomes a foreign key in the entity it was removed from.
- Transitive dependencies can appear in any entity created earlier and must be removed.
- Once transitive dependencies are eliminated, the structure complies fully with the normalisation principle.
Normalization Example for School Purchases
Unormalized Form
| StudentID | StudentName | PurchaseDate | ItemsPurchased | PaymentMethod |
|---|---|---|---|---|
| 101 | Alice Smith | 2024-05-10 | Pen, Notebook | Card |
| 102 | Ben Wong | 2024-05-11 | Pencil | Cash |
| 101 | Alice Smith | 2024-05-12 | Ruler | Card |
First Normal Form
Step 1: Make it Atomic
| StudentID | StudentName | PurchaseDate | ItemsPurchased | PaymentMethod |
|---|---|---|---|---|
| 101 | Alice Smith | 2024-05-10 | Pen | Card |
| 101 | Alice Smith | 2024-05-10 | Notebook | Card |
| 102 | Ben Wong | 2024-05-11 | Pencil | Cash |
| 101 | Alice Smith | 2024-05-12 | Ruler | Card |
Step 2: Remove Repeated Student Info
Student Table (PK: StudentID):
| StudentID | StudentName |
|---|---|
| 101 | Alice Smith |
| 102 | Ben Wong |
Purchases (PK StudentID and ItemsPurchased), (FK StudentID):
| StudentID | PurchaseDate | ItemsPurcahsed | PaymentMethod |
|---|---|---|---|
| 101 | 2024-05-10 | Pen | Card |
| 101 | 2024-05-10 | Notebook | Card |
| 102 | 2024-05-11 | Pencil | Cash |
| 101 | 2024-05-12 | Ruler | Card |
Second Normal Form
- Student Table is fine
- Split Purchases Table into: Purchases (the receipt), and PurchasedItems (the line items in the receipt)
Purchases (PK PurchaseID), (FK StudentID)
| PurchaseID | StudentID | PurchaseDate | PaymentMethod |
|---|---|---|---|
| 1 | 101 | 2024-05-10 | Card |
| 2 | 102 | 2024=05-11 | Cash |
| 3 | 101 | 2024-05-12 | Card |
PurchasedItems (PK PurchaseID and Item)
Creates Transitive Dependancy
| PurchaseID | Item |
|---|---|
| 1 | Pen |
| 1 | Notebook |
| 2 | Pencil |
| 3 | Ruler |
Third Normal Form
- Tables that are good: Purchases and Students
- Add new table: Items
- Update PurchasedItems Table
Items Table (PK ItemID)
| ItemID | ItemName | UnitPrice |
|---|---|---|
| 1 | Pen | 2.00 |
| 2 | Notebook | 6.00 |
| 3 | Pencil | 1.50 |
| 4 | Ruler | 2.00 |
PurchasedItems Table (PK PurchaseID and ItemID), (FK PurchaseID, FK ItemID)
| PurchaseID | ItemID | Quantity |
|---|---|---|
| 1 | 1 | 1 |
| 1 | 2 | 1 |
| 2 | 3 | 1 |
| 3 | 4 | 1 |
- Now item details no longer depend of the purchase.
- Purchases don’t Repeat student details.
- All items depend entirely on the primary key.
Normalization Issues and Solutions
- Data Duplication: Normalization reduces redundancy by eliminating duplicate data.
- Missing Data: Ensures that all necessary data is stored in appropriate tables.
- Dependency Concerns:
- Data Dependencies: Addressed by ensuring functional dependencies are properly managed.
- Composite Key Dependencies: Resolved in 2NF by removing partial-key dependencies.
- Transitive Dependencies: Eliminated in 3NF by creating separate tables for transitive relationships.
- What are the key differences between 1NF, 2NF, and 3NF?
- How do partial-key and transitive dependencies affect database design?
- Why is normalization important in preventing data anomalies?