Second normal form (2NF): remove partial dependencies
Overview
Assuming 1NF, 2NF prohibits a non-prime attribute from depending on a proper subset of any candidate key. Prime means appearing in at least one candidate key. Reuse V47: R(L,C,N,T,I,M,S), with F={L→N,C→TI,I→M,LC→S}. LC is the only candidate key; N, T, I, M and S are non-prime. L→N and C→TI violate 2NF, as does the implied C→M. Load the two fixtures as in lesson 1.
First example
SELECT course_id, COUNT(*)FROM fd_enrollment GROUP BY course_idHAVING COUNT(*) > 1 ORDER BY course_id;Observed SQLite result (rows in JSON):
[ [ 10, 2 ]]How it works
Decompose into Learner(L,N), CourseStage(C,T,I,M) and Enrollment(L,C,S). The original stores course 10 twice. The second query joins the three relations to reconstruct the enrollment facts. CourseStage is in 2NF under the declared dependencies (key C), but I→M still causes instructor-name repetition. Enrollment has no partial dependency of S. This split is a deliberate intermediate step, not the finished design. Check all candidate keys, not just the selected primary key: adding a surrogate ID does not remove a partial dependency on a remaining business candidate key. A dependency on the empty set, if present, must also be considered.
Practical example
SELECT e.learner_id, e.course_id, l.name, c.title, c.instructor_id, c.instructor_name, e.statusFROM norm_enrollment eJOIN norm_learner l ON l.id=e.learner_idJOIN norm_course_stage c ON c.id=e.course_idORDER BY e.learner_id,e.course_id;Observed SQLite result (rows in JSON):
[ [ 1, 10, "Mina", "SQL Basics", 1, "Neda", "active" ], [ 1, 11, "Mina", "SQL Reports", 1, "Neda", "completed" ], [ 2, 10, "Mina", "SQL Basics", 1, "Neda", "active" ], [ 3, 12, "Omid", "SQL Design", 2, "Reza", "active" ]]Practice and mistakes
Practice: explain why S belongs with LC rather than L alone. Compare original and reconstructed rows using EXCEPT in both directions. The original fixture has four enrollment rows; no differences are expected. Next, remove the instructor-name dependency.