Functional dependencies: determinants and attribute closure
Overview
A functional dependency X → Y means that any two tuples agreeing on X must agree on Y in every legal instance of a relation. X is the determinant; it need not be a key. For a training center, assume each learner ID determines one learner name, each course ID determines its title and instructor ID, each instructor ID determines one name, and each learner/course pair determines one enrollment status. Load fd-enrollment.sql in disposable SQLite; the deliberately redundant table contains non-NULL attributes only.
First example
SELECT course_idFROM fd_enrollmentGROUP BY course_idHAVING COUNT(DISTINCT course_title)>1ORDER BY course_id;Observed SQLite result (rows in JSON):
[]How it works
Use symbols L=learner_id, C=course_id, N=learner_name, T=course_title, I=instructor_id, M=instructor_name and S=status. Given F={L→N, C→TI, I→M, LC→S}, start C⁺={C}, add T and I, then M; no rule adds more, so C⁺={C,T,I,M}. Start LC⁺={L,C}; add N,T,I,S and then M: all seven attributes. Repeat until no new attribute appears; an empty determinant is allowed in theory. The first SQL query checks C→T on the current rows, the second constructs a hypothetical conflicting title without changing the table. COUNT(DISTINCT) ignores NULL; this diagnostic is suitable here only because the attributes are non-NULL. A counterexample disproves a proposed FD for legal data; a clean sample cannot prove a business rule.
Practical example
WITH sample AS ( SELECT course_id, course_title FROM fd_enrollment UNION ALL SELECT 10, 'Wrong title')SELECT course_id, COUNT(DISTINCT course_title)FROM sample GROUP BY course_idHAVING COUNT(DISTINCT course_title)>1ORDER BY course_id;Observed SQLite result (rows in JSON):
[ [ 10, 2 ]]Practice and mistakes
Practice: calculate I⁺ and L⁺ by hand. Expected {I,M} and {L,N}. Explain why names need not identify learners. Do not infer the reverse of a dependency. See the candidate-key lesson next.