📗 Second Normal Form (2NF)
2NF (Second Normal Form) builds on 1NF and adds one more rule:
A table is in 2NF if:
- It is in 1NF, and
- All non-key attributes are fully functionally dependent on the entire primary key.
🔍 What Does “Fully Dependent” Mean?
If the primary key is composite (made of two or more columns), then:
- A non-key column must depend on both parts of the key, not just one.
❌ Example: Not in 2NF
Table: StudentCourses
StudentID | CourseID | StudentName | CourseName |
---|
1 | CS101 | Alice | Java |
1 | CS102 | Alice | SQL |
2 | CS101 | Bob | Java |
- Composite Primary Key: (
StudentID
, CourseID
) - Problem:
StudentName
depends only on StudentID
CourseName
depends only on CourseID
❌ These are partial dependencies, so this table is not in 2NF.
✅ Convert to 2NF: Split into Two Tables
Table: Students
StudentID | StudentName |
---|
1 | Alice |
2 | Bob |
Table: Courses
CourseID | CourseName |
---|
CS101 | Java |
CS102 | SQL |
Table: StudentCourses
StudentID | CourseID |
---|
1 | CS101 |
1 | CS102 |
2 | CS101 |
- ✅ Now, all non-key attributes fully depend on their entire primary key.
- ✅ This structure is in 2NF.
💡 Summary:
Normal Form | Key Rule |
---|
1NF | Atomic values, no repeating groups |
2NF | No partial dependency on a composite key |