Functional Dependency
Step 7 in the Databases path · 4 concepts · 0 problems
📘 Learn Functional Dependency from zero
Start from zero. A functional dependency is a rule that says: "if you know the value of one column (or set of columns), you automatically know the value of another." We write it X → Y, read "X determines Y." Precisely: in any legal table, any two rows that agree on all of X must agree on all of Y.
Analogy — a vending machine. Press a button code (X) and you always get the same snack (Y). B4 today gives pretzels; B4 tomorrow still pretzels. The code functionally determines the snack. The reverse fails — pretzels might also come from B7 — so Snack → Code does not hold. That one-directional "same input ⟹ same output" is exactly a function, hence functional dependency.
Worked example. Table Student(RollNo, Name, Dept, DeptHead). Real-world semantics: each roll number is one student in one department; each department has one head. So:
RollNo → Name(one roll number names one student)RollNo → DeptDept → DeptHead(one head per department)
Does RollNo → DeptHead hold? Yes — RollNo fixes Dept and Dept fixes DeptHead, so the dependency chains. This is transitivity, one of Armstrong's three primary inference rules: reflexivity (if Y ⊆ X then X → Y — these are the trivial FDs), augmentation (if X → Y then XZ → YZ), and transitivity (if X → Y and Y → Z then X → Z). These axioms are sound (derive only valid FDs) and complete (derive all valid FDs); the handy secondary rules — union, decomposition, pseudotransitivity — follow from them. By contrast Dept → RollNo fails: one department has many students, so the determinant does not pin down one roll number.
Key insight: a functional dependency is a semantic promise about the real world — "same left side forces same right side, for every possible row" — not a coincidence in today's data. Keys, the FD taxonomy (trivial vs. non-trivial; full vs. partial; transitive), and all of normalization are built on this one idea.
✨ Added by the guide to build intuition — not from the source course.
🎯 Guided practice
Easy — verify an FD against a table. Relation
R(A, B, C)with rows(1, x, true),(2, y, false),(1, x, true),(3, x, false). DoesA → Bhold? DoesB → Chold?Reasoning (core pattern: group by the determinant, check the dependent). For
A → B: group byA.A=1appears twice, both withB=x— consistent;A=2→yandA=3→xare singletons. No two rows shareAyet differ onB, soA → Bholds (for this instance). ForB → C: group byB.B=xappears in rows 1, 3, 4 withC = true, true, false— sameB, differentC. That is a counterexample, soB → Cdoes not hold. Caveat: a single instance can only refute an FD or fail to refute it; it can never prove one holds for all legal instances — that comes from semantics. Pattern: an FD is violated the instant you find two rows equal on the left and unequal on the right.Medium — find a candidate key via attribute closure.
R(A, B, C, D, E)withF = { A → B, B → C, CD → E, E → A }. Is{C, D}a candidate key?Reasoning (core pattern: compute the closure
X⁺, then check minimality). Initialize{C,D}⁺ = {C, D}. Repeatedly apply any FD whose entire left side is already in the set:CD → E⟹ addE→{C,D,E};E → A⟹ addA→{A,C,D,E};A → B⟹ addB→{A,B,C,D,E};B → Cadds nothing. Closure = all five attributes, so{C,D}is a superkey. Now check minimality: is any proper subset already a superkey?{C}⁺ = {C}(no FD fires withoutD),{D}⁺ = {D}. Neither single attribute determines everything, so{C,D}is irreducible — therefore a candidate key. Pattern:Xis a candidate key iffX⁺= all attributes AND no proper subset has that property. (This same closure also answers "doesX → Yfollow fromF?" — yes iffY ⊆ X⁺, which is why we never enumerate the exponentialF⁺.)
✨ Added by the guide — work these before the full problem set.