In database management, Normalization is the process of organizing data to minimize redundancy and dependency. It involves dividing a database into smaller tables and defining relationships between them to eliminate data anomalies. The stages of normalization are called normal forms (NF), each building upon the previous one with stricter requirements.
1. First Normal Form (1NF)
A relation is in 1NF if:
- The table has a primary key.
- All attributes (columns) contain atomic (indivisible) values.
- There are no repeating groups or arrays (each field contains a single value).
Example:
StudentID | Subjects |
---|---|
101 | Math, Science |
102 | English |
This table is not in 1NF because the “Subjects” column contains multiple values. To convert it to 1NF:
StudentID | Subject |
---|---|
101 | Math |
101 | Science |
102 | English |
2. Second Normal Form (2NF)
A table is in 2NF if:
- It is in 1NF.
- All non-key attributes are fully dependent on the primary key (no partial dependency).
Example:
OrderID | ProductID | ProductName | Quantity |
---|---|---|---|
1 | P1 | Laptop | 2 |
1 | P2 | Mouse | 1 |
Here, “ProductName” depends only on “ProductID,” not on the composite key (“OrderID, ProductID”). To convert it to 2NF:
Orders Table:
OrderID | ProductID | Quantity |
---|---|---|
1 | P1 | 2 |
1 | P2 | 1 |
Products Table:
ProductID | ProductName |
---|---|
P1 | Laptop |
P2 | Mouse |
3. Third Normal Form (3NF)
A table is in 3NF if:
- It is in 2NF.
- There is no transitive dependency (non-key attributes depend only on the primary key).
Example:
StudentID | StudentName | DeptID | DeptName |
---|---|---|---|
101 | Alice | D1 | Science |
102 | Bob | D2 | Arts |
Here, “DeptName” is dependent on “DeptID,” which is not the primary key. To convert it to 3NF:
Students Table:
StudentID | StudentName | DeptID |
---|---|---|
101 | Alice | D1 |
102 | Bob | D2 |
Departments Table:
DeptID | DeptName |
---|---|
D1 | Science |
D2 | Arts |
4. Boyce-Codd Normal Form (BCNF)
A table is in BCNF if:
- It is in 3NF.
- Every determinant is a candidate key (a determinant is an attribute that uniquely identifies another attribute).
Example:
TeacherID | Subject | DeptID |
---|---|---|
T1 | Math | D1 |
T2 | Science | D1 |
T3 | Math | D2 |
Here, “Subject” determines “DeptID,” but “Subject” is not a candidate key. To convert it to BCNF:
Teachers Table:
TeacherID | Subject |
---|---|
T1 | Math |
T2 | Science |
T3 | Math |
Subjects Table:
Subject | DeptID |
---|---|
Math | D1 |
Science | D1 |
Math | D2 |
5. Fourth Normal Form (4NF)
A table is in 4NF if:
- It is in BCNF.
- It has no multi-valued dependencies (an attribute must not have two or more independent multi-valued attributes for the same primary key).
Example:
StudentID | Course | Hobby |
---|---|---|
101 | Math | Painting |
101 | Science | Painting |
101 | Math | Dancing |
Here, “Course” and “Hobby” are independent of each other but linked by the same primary key. To convert it to 4NF:
Courses Table:
StudentID | Course |
---|---|
101 | Math |
101 | Science |
Hobbies Table:
StudentID | Hobby |
---|---|
101 | Painting |
101 | Dancing |
6. Fifth Normal Form (5NF)
A table is in 5NF if:
- It is in 4NF.
- It cannot have any join dependency that is not implied by candidate keys.
This occurs in cases where data can be split into smaller tables without losing any information.
6. Sixth Normal Form (6NF)
Rarely used in practice, 6NF ensures that a table is free of non-trivial join dependencies, often used in specialized temporal databases.
Summary of Normal Forms
Normal Form | Requirements |
---|---|
1NF | Atomic values, no repeating groups |
2NF | 1NF + no partial dependencies |
3NF | 2NF + no transitive dependencies |
BCNF | 3NF + every determinant is a candidate key |
4NF | BCNF + no multi-valued dependencies |
5NF | 4NF + no join dependencies |
6NF | 5NF + eliminates all non-trivial join dependencies (rarely used) |
Each normal form reduces redundancy and improves data integrity, making the database more efficient and easier to maintain. Let me know if you need more examples or clarification! 😊