Third normal form (3NF): determinants and prime attributes
Overview
For a 1NF relation, 3NF requires that every implied nontrivial dependency X→A has either a superkey X or a prime attribute A. A nontrivial dependency has A outside X. In CourseStage(C,T,I,M), C is the only candidate key, and I→M violates 3NF because I is not a superkey and M is non-prime. This is a transitive dependency through instructor ID. Load the fixtures from lesson 1.
First example
SELECT instructor_id, COUNT(*)FROM norm_course_stage GROUP BY instructor_idHAVING COUNT(*)>1 ORDER BY instructor_id;Observed SQLite result (rows in JSON):
[ [ 1, 2 ]]How it works
Separate Course(C,T,I) and Instructor(I,M). The first query shows repeated instructor facts in the intermediate design. The second reconstructs them from separate tables with a join. In the final schema, norm_enrollment_final references norm_course instead of norm_course_stage. Learner, Enrollment, Course and Instructor now each satisfy BCNF under the stated FDs. Their keys enforce those local dependencies and foreign keys enforce references. An instructor can exist before teaching a course; updating their name requires one row change. Do not equate 3NF with a ban on every transitive inference: the prime-attribute exception is important, as the next lesson shows. A sample join proves only the sample reconstruction; formal losslessness is a separate property.
Practical example
SELECT c.id,c.title,i.nameFROM norm_course c JOIN norm_instructor i ON i.id=c.instructor_idORDER BY c.id;Observed SQLite result (rows in JSON):
[ [ 10, "SQL Basics", "Neda" ], [ 11, "SQL Reports", "Neda" ], [ 12, "SQL Design", "Reza" ]]Practice and mistakes
Practice: update instructor 1 in norm_instructor inside a disposable transaction, query both courses and roll back. Both should show the same changed name. Explain why a separate instructor table avoids inconsistent names.