What is Normalization in a database application
Goal: Ensure that the table has atomic values (no multi-valued attributes) and all rows are unique.
Rules:
Example (Non-1NF table):
OrderID | CustomerName | PhoneNumbers | ProductName |
---|---|---|---|
1 | John | 123-4567, 234-5678 | TV, Mobile |
2 | Mary | 345-6789 | Laptop |
Problems:
PhoneNumbers
column has multiple values.ProductName
column has multiple values.PhoneNumbers and ProductName should have only one value per row.
OrderID | CustomerName | PhoneNumber | ProductName |
---|---|---|---|
1 | John | 123-4567 | TV |
1 | John | 234-5678 | Mobile |
2 | Mary | 345-6789 | Laptop |
Now, each column contains atomic values, and there are no repeating groups.
Goal: Ensure that the table is in 1NF, and all non-key columns are fully dependent on the entire primary key (not partially dependent).
Rules:
Example (Non-2NF table):
OrderID | ProductID | ProductName | CustomerName |
---|---|---|---|
1 | 101 | TV | John |
2 | 102 | Mobile | John |
3 | 103 | Laptop | Mary |
To achieve 2NF:
Products Table:
ProductID | ProductName |
---|---|
101 | TV |
102 | Mobile |
103 | Laptop |
Orders Table:
OrderID | ProductID | CustomerName |
---|---|---|
1 | 101 | John |
2 | 102 | John |
3 | 103 | Mary |
Now, every non-key attribute is fully dependent on the entire primary key.
Goal: Eliminate transitive dependencies (non-key columns should not depend on other non-key columns).
Rules:
Example (Non-3NF table):
OrderID | CustomerID | CustomerName | CustomerAddress |
---|---|---|---|
1 | 201 | John | 123 Main St |
2 | 202 | Mary | 456 Oak St |
To achieve 3NF:
Customers Table:
CustomerID | CustomerName | CustomerAddress |
---|---|---|
201 | John | 123 Main St |
202 | Mary | 456 Oak St |
Orders Table:
OrderID | CustomerID |
---|---|
1 | 201 |
2 | 202 |
Now, there are no transitive dependencies:
Summary