Skip to content
Chethan Yadav_
Database Management Systems

DBMS/Lesson 5 of 9/6 min read

Functional Dependencies and Normalization

Anomalies, functional dependencies, Armstrong's axioms, attribute closure, finding candidate keys, 1NF to BCNF, 4NF, 5NF, lossless and dependency-preserving decomposition, and denormalization.


On this page

Why normalize: Update Anomalies

Consider one table holding everything:

student_idnamecourse_idcourse_nameinstructor
1AshaC1DBMSRao
1AshaC2OSIyer
2RaviC1DBMSRao

Problems (anomalies):

  • Insertion anomaly: cannot add a new course until some student enrolls.
  • Deletion anomaly: deleting Ravi's only enrollment might delete the fact that C1 exists.
  • Update anomaly: changing C1's instructor needs many row updates; missing one causes inconsistency.

Normalization decomposes tables to remove redundancy and these anomalies, guided by functional dependencies.

Functional Dependency

A functional dependency (FD) X -> Y means: if two tuples agree on X, they must agree on Y. X determines Y.

Examples: student_id -> name, course_id -> course_name, instructor.

  • Trivial FD: Y is a subset of X ({A, B} -> A).
  • Non-trivial: Y not a subset of X.
  • Fully functional: Y depends on all of X, not a proper subset.

Armstrong's Axioms

Sound and complete inference rules for FDs:

  1. Reflexivity: if Y ⊆ X then X -> Y.
  2. Augmentation: if X -> Y then XZ -> YZ.
  3. Transitivity: if X -> Y and Y -> Z then X -> Z.

Derived rules: union (X -> Y, X -> Z gives X -> YZ), decomposition (X -> YZ gives X -> Y), pseudotransitivity (X -> Y, WY -> Z gives WX -> Z).

Attribute Closure

The closure X+ is the set of all attributes functionally determined by X.

Algorithm: start with X+ = X; repeatedly, for each FD A -> B with A ⊆ X+, add B; stop when nothing changes.

Example: R(A, B, C, D, E) with A -> B, B -> C, CD -> E.

{A}+    = {A, B, C}
{A, D}+ = {A, D, B, C, E}   -> all attributes, so AD is a super key

Finding candidate keys

  1. Attributes that never appear on any right side must be in every key (here A, D).
  2. Compute their closure. If it covers everything, it is the only candidate key: AD.
  3. Otherwise add other attributes one at a time and test minimality.

Minimal Cover

A minimal (canonical) cover is a simplified equivalent set of FDs:

  1. Split right sides into single attributes.
  2. Remove extraneous attributes from left sides.
  3. Remove redundant FDs.

It is used to synthesize 3NF tables.

First Normal Form

1NF: every attribute holds only atomic (indivisible) values; no repeating groups or multi-valued cells.

Violation: phone = "98..., 99...". Fix: one row per phone or a separate phone table.

Second Normal Form

2NF: in 1NF and no partial dependency: no non-prime attribute depends on only part of a candidate key.

Partial Dependency

With key (student_id, course_id), the FD course_id -> course_name is partial. Fix: move it out.

Enrollment(student_id, course_id)
Course(course_id, course_name, instructor)
Student(student_id, name)

A table whose candidate keys are all single attributes is automatically in 2NF.

Third Normal Form

3NF: in 2NF and no transitive dependency of a non-prime attribute on a key.

Formal test: for every non-trivial FD X -> A, either X is a super key, or A is a prime attribute.

Transitive Dependency

emp_id -> dept_id and dept_id -> dept_name, so emp_id -> dept_name transitively. Fix:

Employee(emp_id, name, dept_id)
Department(dept_id, dept_name)

BCNF

Boyce-Codd Normal Form: for every non-trivial FD X -> A, X must be a super key. Stricter than 3NF (drops the "A is prime" escape).

Example in 3NF but not BCNF: Teaches(student, subject, teacher) with (student, subject) -> teacher and teacher -> subject (each teacher teaches one subject). teacher is not a super key, but subject is prime, so 3NF holds and BCNF fails. Decompose to (teacher, subject) and (student, teacher).

3NF decomposition can always be lossless and dependency preserving. BCNF is always lossless but may lose some dependencies. That trade-off is why 3NF is often the practical target.

4NF

Multivalued Dependency

A multivalued dependency (MVD) X ->> Y means for each X, the set of Y values is independent of the other attributes. Example: an employee's skills and languages are independent lists.

4NF: in BCNF and no non-trivial MVD where X is not a super key. Fix: split Emp(emp, skill, language) into EmpSkill(emp, skill) and EmpLang(emp, language).

5NF (PJNF): no join dependency that is not implied by candidate keys; the table cannot be decomposed further without loss. Rare in practice.

Normal forms summary

FormRule
1NFAtomic values
2NF1NF + no partial dependency on a key
3NF2NF + no transitive dependency (or RHS is prime)
BCNFEvery determinant is a super key
4NFBCNF + no non-trivial multivalued dependency
5NFNo non-trivial join dependency

Decomposition properties

Lossless Decomposition

Splitting R into R1 and R2 is lossless (lossless join) if joining them gives back exactly R, with no spurious tuples.

Test: decomposition is lossless if R1 ∩ R2 -> R1 or R1 ∩ R2 -> R2, i.e. the common attributes form a key of at least one part.

Dependency Preservation

A decomposition is dependency preserving if every original FD can be checked within one of the new tables without a join. If not, enforcing the constraint needs expensive joins.

Denormalization

Denormalization deliberately adds redundancy to speed up reads: duplicate a dept_name into employee, keep precomputed counters, use materialized views. Common in analytics (star schemas) and read-heavy systems. Cost: more storage and harder, riskier writes.

Quick revision

  • Normalization removes insertion, deletion and update anomalies.
  • 2NF kills partial dependencies, 3NF transitive, BCNF any non-key determinant.
  • Lossless if the common attributes are a key of one side.
  • BCNF may not preserve dependencies; 3NF always can.