- Published on
Database Normalization: 2NF
Second Normal Form (2NF) is a step in database normalization that builds upon the First Normal Form (1NF). It aims to eliminate partial dependencies to reduce redundancy and improve data integrity.
✅ 1. Requirements for 2NF
A table is in Second Normal Form if:
- It is already in First Normal Form (1NF).
- Every non-prime attribute is fully functionally dependent on the entire primary key, not just a part of it.
🔍 Key Concepts
- 1NF: All values are atomic (no arrays, repeating groups).
- Partial Dependency: A non-prime attribute depends on part of a composite key.
- Non-prime Attribute: A column that is not part of any candidate key.
📊 Example
🚫 Not in 2NF
| StudentID | CourseID | StudentName | CourseName |
|---|---|---|---|
| 1 | CS101 | Alice | Database |
| 2 | CS101 | Bob | Database |
| 1 | MA201 | Alice | Algebra |
- Primary Key:
(StudentID, CourseID) StudentNamedepends only on StudentIDCourseNamedepends only on CourseID
Problem: StudentName and CourseName have partial dependencies, violating 2NF.
✅ In 2NF (After Decomposition)
Student Table: | StudentID | StudentName | |-----------|-------------| | 1 | Alice | | 2 | Bob |
Course Table: | CourseID | CourseName | |----------|------------| | CS101 | Database | | MA201 | Algebra |
Enrollment Table: | StudentID | CourseID | |-----------|----------| | 1 | CS101 | | 2 | CS101 | | 1 | MA201 |
🧠 Summary
| Normal Form | Removes | Ensures |
|---|---|---|
| 1NF | Repeating groups, non-atomic fields | Atomic values |
| 2NF | Partial dependencies | Full dependency on the whole key |