Normalization: 2NF
Second normal form removes dependencies on only part of a composite key. If a non-key attribute depends on half the key, it belongs in another table.
In plain English
If a fact belongs to only half of a two-part key, give it its own table.
The one idea
Second normal form removes partial dependencies: a non-key attribute must depend on the whole composite key, not just part of it.
A fact about a course does not belong in every enrollment row. Partial dependencies duplicate that fact once per student.
By the end
- 01Identify a composite primary key.
- 02Detect a partial dependency.
- 03Decompose a relation into 2NF.
- 04Explain why 1NF is a prerequisite.
The rule
A relation is in 2NF if it is in 1NF and every non-key attribute is fully functionally dependent on the whole primary key. If the primary key is a single attribute, 2NF is automatic. Partial dependencies only matter with composite keys.
A partial dependency example
Enrollment(student_id, course_id, student_name, course_name, grade) has primary key (student_id, course_id). student_name depends only on student_id; course_name depends only on course_id. Both are partial dependencies. grade depends on the full key.
(student_id, course_id) -> grade full dependency
student_id -> student_name partial
course_id -> course_name partialDecomposition
Split the partial dependencies into their own relations: Student(student_id, student_name), Course(course_id, course_name), and Enrollment(student_id, course_id, grade). The enrollment table keeps the full-key dependency; the others keep the single-attribute dependencies.
Student(student_id, student_name)
Course(course_id, course_name)
Enrollment(student_id, course_id, grade)Enrollment with course names
Enrollment(student_id, course_id, student_name, course_name, grade) has composite key (student_id, course_id).
Check student_name against the key.
It depends only on student_id, so it is a partial dependency.
Check course_name against the key.
It depends only on course_id, another partial dependency.
Split Student, Course, and Enrollment.
Grade remains in Enrollment because it depends on both parts of the key.
Conclusion2NF is about composite keys. If a relation has a single-attribute key, it is automatically in 2NF once it is in 1NF.
Instrument
Watch it happen.
Step through one operation at a time
Start with the 2NF target table
The table violates 2NF: no partial dependency.
| student_id | course_id | student_name | course_name | grade |
|---|---|---|---|---|
| 1 | C1 | Ada | DBMS | A |
| 1 | C2 | Ada | OS | B |
| 2 | C1 | Grace | DBMS | A |
The trade-off
No free correctness.
Gain
Course facts and student facts are stored once.
Cost
Queries that want all three facts must join three relations.
Verdict
Decompose partial dependencies; keep the relationship fact in the junction relation.
Recap
What to keep.
Takeaways
- +2NF removes partial dependencies on a composite key.
- +A relation with a single-attribute key is automatically in 2NF if it is in 1NF.
- +Decompose each partial dependency into its own relation.
- +The junction table keeps the full-key dependency.
- +2NF reduces redundancy and update anomalies.
Traps
- !Applying 2NF to a single-attribute key and expecting changes.
- !Forgetting that 1NF is a prerequisite.
- !Losing the relationship between the decomposed tables.
Focus
- →Identify the composite key.
- →Test each non-key attribute for full dependency.
- →Decompose and preserve the junction table.
Check yourself
Before you turn the page.
What does 2NF remove?
If a relation has a single-attribute primary key and is in 1NF, is it in 2NF?