Database Normalization
In databases, 1N, 2N, 3N refer to 1NF, 2NF, 3NF β the first three normal forms in database normalization. These are rules to organize relational data efficiently and eliminate redundancy.
β 1NF (First Normal Form)
π Rule:
- Each column should have atomic (indivisible) values.
- No repeating groups or arrays in a single column.
β Bad Example:
| ID | Name | Phone Numbers |
|---|---|---|
| 1 | Aftab | 12345, 67890 |
β Good Example (1NF applied):
| ID | Name | Phone |
|---|---|---|
| 1 | Aftab | 12345 |
| 1 | Aftab | 67890 |
β 2NF (Second Normal Form)
π Rule:
- Be in 1NF
- Remove partial dependencies (i.e., non-key columns should depend on the whole primary key)
β Bad Example (composite key: OrderID, ProductID):
| OrderID | ProductID | ProductName | CustomerName |
|---|---|---|---|
| 1 | 101 | Mouse | Aftab |
Β
β‘οΈΒ CustomerName depends only on OrderID, not the full composite key.
β Fix:
Split into:
- Order table (OrderID, CustomerName)
- OrderDetails table (OrderID, ProductID, ProductName)
β 3NF (Third Normal Form)
π Rule:
- Be in 2NF
- No transitive dependencies (i.e., non-key columns shouldnβt depend on other non-key columns)
β Bad Example:
| StudentID | Name | Department | HOD |
|---|---|---|---|
| 1 | Raj | IT | Dr. Mehta |
Β
β‘οΈ HOD depends on Department, not directly on StudentID.
β Fix:
Split into:
-
Studenttable (StudentID, Name, Department) -
Departmenttable (Department, HOD)
π§ Summary Table:
| Normal Form | Goal | Fixes |
|---|---|---|
| 1NF | Atomic values | No arrays or multi-values |
| 2NF | Full key dependency | Remove partial dependencies |
| 3NF | No transitive dependencies | Normalize non-key columns |