Normalization is the process of organizing data within a relational database to minimize redundancy and improve data integrity. This is achieved by dividing larger tables into smaller, related tables and establishing relationships between them through foreign keys. The primary aim is to eliminate data anomalies during insertions, deletions, and updates, thereby making the database more efficient and consistent.
๐น First Normal Form (1NF):
1NF ensures that each column contains atomic (indivisible) values, and each record is unique. Repeating groups or arrays are not allowed in any row.
Before 1NF:
StudentID Name Courses
101 Alice Math, English
After 1NF:
StudentID Name Course
101 Alice Math
101 Alice English
๐น Second Normal Form (2NF):
A table is in 2NF if it is already in 1NF and there are no partial dependencies. A partial dependency exists when a non-prime attribute is dependent on a part of a composite primary key.
Before 2NF:
StudentID CourseID StudentName CourseName
Here, StudentName depends only on StudentID and CourseName only on CourseID.
After 2NF:
Student Table: (StudentID, StudentName)
Course Table: (CourseID, CourseName)
Enrollment Table: (StudentID, CourseID)
๐น Third Normal Form (3NF):
A table is in 3NF if it is in 2NF and there are no transitive dependencies. A transitive dependency occurs when a non-prime attribute depends on another non-prime attribute.
Before 3NF:
EmpID EmpName DeptID DeptName
Here, DeptName is dependent on DeptID, which is not a key โ this is a transitive dependency.
After 3NF:
Employee Table: (EmpID, EmpName, DeptID)
Department Table: (DeptID, DeptName)
๐น Boyce-Codd Normal Form (BCNF):
BCNF is a stricter version of 3NF. It ensures that every determinant in the table is a candidate key. A determinant is any attribute on which another attribute is functionally dependent.
Before BCNF:
Course Instructor Room
Assume one instructor teaches one course, but a room can host multiple courses. Instructor โ Course is valid, but Instructor is not a candidate key, thus violating BCNF.
After BCNF:
Instructor-Course Table: (Instructor, Course)
Course-Room Table: (Course, Room)
โ
Benefits of Normalization:
- Eliminates redundant data.
- Reduces update, insertion, and deletion anomalies.
- Improves query performance and data consistency.
- Enhances database scalability and maintainability.
Normalization is an essential part of database design that ensures clean, efficient, and well-structured relational databases.