1. Home
  2. Explore
  3. Computer Science
  4. Functional Dependencies

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Functional Dependencies

Functional Dependencies and Relational Schema Design

Functional dependencies

A functional dependency (FD) expresses a constraint between sets of attributes in a relation. An FD written as α→β\alpha \to \betaα→β means that the values of attributes in α\alphaα determine the values of attributes in β\betaβ.

More precisely, in every valid instance of the relation, any two tuples that agree on all attributes in α\alphaα must also agree on all attributes in β\betaβ. The constraint applies to every valid instance of the schema, not just to one observed dataset.

For example, if A→BA \to BA→B and B→CB \to CB→C, then AAA determines CCC: tuples that agree on AAA must agree on BBB, and therefore must agree on CCC.


Armstrong’s axioms and the closure of functional dependencies

Armstrong’s axioms are a sound and complete set of rules for deriving functional dependencies from a given set FFF.

  • Reflexivity: If β⊆α\beta \subseteq \alphaβ⊆α, then α→β\alpha \to \betaα→β. This captures dependencies that hold simply because the right-hand attributes are already among the left-hand attributes.

  • Augmentation: If α→β\alpha \to \betaα→β, then αγ→βγ\alpha\gamma \to \beta\gammaαγ→βγ for any set of attributes γ\gammaγ. Adding the same attributes to both sides preserves the dependency.

  • Transitivity: If α→β\alpha \to \betaα→β and β→γ\beta \to \gammaβ→γ, then α→γ\alpha \to \gammaα→γ.

The closure of a set of functional dependencies, written F+F^+F+, is the set of all dependencies logically implied by FFF. It includes the original dependencies and every dependency that can be derived from them.

Because the schema has finitely many attributes, only finitely many distinct dependencies can be formed. A procedure that repeatedly applies Armstrong’s axioms must eventually stop: it terminates when no new dependencies can be added to F+F^+F+.

A direct closure procedure

A simple, though potentially inefficient, method is:

  1. Initialize the current set with FFF.

  2. Apply reflexivity and augmentation to individual dependencies.

  3. Apply transitivity to pairs of dependencies where the right side of one can connect to the left side of another.

  4. Add any newly derived dependencies.

  5. Repeat until the set no longer changes.

This procedure illustrates how dependencies accumulate through repeated inference. More efficient methods are useful in practice, but the closure provides a precise account of everything implied by FFF.

Derived rules

Several useful rules follow from Armstrong’s axioms. They are sound—they derive only dependencies that hold—but they are not needed as additional axioms because they can be proved from the original three.

  • Union: If α→β\alpha \to \betaα→β and α→γ\alpha \to \gammaα→γ, then α→βγ\alpha \to \beta\gammaα→βγ. A common left side can determine the union of the right sides.

  • Decomposition: If α→βγ\alpha \to \beta\gammaα→βγ, then both α→β\alpha \to \betaα→β and α→γ\alpha \to \gammaα→γ. A dependency on a set of attributes implies a dependency on each subset.

  • Pseudotransitivity: If α→β\alpha \to \betaα→β and γβ→δ\gamma\beta \to \deltaγβ→δ, then γα→δ\gamma\alpha \to \deltaγα→δ.

For example, union follows because tuples that agree on α\alphaα must agree on both β\betaβ and γ‘,andthusontheirunion.Itcanalsobederivedfromtheaxioms:augment\gamma`, and thus on their union. It can also be derived from the axioms: augmentγ‘,andthusontheirunion.Itcanalsobederivedfromtheaxioms:augment\alpha \to \betawithwithwith\alpha,obtaining, obtaining,obtaining\alpha \to \alpha\beta;augment; augment;augment\alpha \to \gammawithwithwith\beta,obtaining, obtaining,obtaining\alpha\beta \to \beta\gamma$; then apply transitivity.


Attribute closure

The closure of an attribute set α\alphaα with respect to FFF, written α+\alpha^+α+, is the set of all attributes that can be functionally determined by α\alphaα using the dependencies in FFF.

The attribute closure is always relative to a specified set of functional dependencies. In other words, α+\alpha^+α+ means the attributes implied by α\alphaα under the dependencies currently being considered.

Computing an attribute closure

A straightforward algorithm is:

  1. Initialize the result to α\alphaα, since every attribute in α\alphaα is determined by α\alphaα.

  2. For each dependency β→γ\beta \to \gammaβ→γ in FFF, check whether β\betaβ is already contained in the result.

  3. If it is, add γ\gammaγ to the result.

  4. Repeat until no attributes can be added.

The logic is that if β\betaβ is already determined by α\alphaα, and β→γ\beta \to \gammaβ→γ, then transitivity implies that α\alphaα determines γ\gammaγ as well.

Example

Suppose the relation has attributes A,B,C,G,H,IA, B, C, G, H, IA,B,C,G,H,I, and the dependencies include:

  • A→BA \to BA→B

  • A→CA \to CA→C

  • CG→HCG \to HCG→H

  • CG→ICG \to ICG→I

To compute (AG)+(AG)^+(AG)+:

  1. Start with {A,G}\{A,G\}{A,G}.

  2. Since AAA determines BBB and CCC, add BBB and CCC.

  3. The result now contains both CCC and GGG, so it contains the left side of CG→HCG \to HCG→H and CG→ICG \to ICG→I. Add HHH and III.

  4. No further attributes can be added.

Thus, (AG)+={A,B,C,G,H,I}(AG)^+ = \{A,B,C,G,H,I\}(AG)+={A,B,C,G,H,I} for this set of dependencies. If these are all the attributes of the relation, then AGAGAG is a superkey.

Uses of attribute closure

Attribute closure is a practical tool for several common questions.

  • Testing for a superkey: A set α\alphaα is a superkey if α+\alpha^+α+ contains every attribute of the relation.

  • Testing whether an FD follows from FFF: The dependency α→β\alpha \to \betaα→β holds if and only if β⊆α+\beta \subseteq \alpha^+β⊆α+.

  • Finding candidate keys: First find sets whose closures cover the entire relation. Then test whether any attributes can be removed while preserving that property.

A candidate key is a minimal superkey: it determines every attribute, but no proper subset of it does.

Testing whether AGAGAG is a candidate key

In the example, (AG)+(AG)^+(AG)+ contains every attribute, so AGAGAG is a superkey. To check minimality, test the proper subsets:

  • A+A^+A+ contains A,B,C,HA,B,C,HA,B,C,H if the dependencies include A→BA \to BA→B, A→CA \to CA→C, and B→HB \to HB→H. It does not contain GGG or III, so AAA is not a superkey.

  • If GGG does not occur on the right side of any dependency, then starting from GGG cannot derive the other attributes, so GGG alone is not a superkey.

Since neither single-attribute subset is a superkey, AGAGAG is minimal and therefore is a candidate key.

Computing F+F^+F+ using attribute closures

Attribute closures can also be used to determine the closure of a dependency set. For each attribute set XXX in the relation, compute X+X^+X+. Every attribute YYY in X+X^+X+ gives a dependency X→YX \to YX→Y in F+F^+F+. Considering all possible sets XXX produces the dependencies implied by FFF.


Boyce–Codd normal form

Boyce–Codd Normal Form (BCNF) is a condition for reducing redundancy in a relational schema. A relation must first satisfy first normal form. It is in BCNF with respect to FFF if, for every dependency α→β\alpha \to \betaα→β in F+F^+F+, at least one of these holds:

  • The dependency is trivial, meaning β⊆α\beta \subseteq \alphaβ⊆α.

  • The left side α\alphaα is a superkey for the relation.

A nontrivial dependency whose left side is not a superkey violates BCNF. The key idea is that, in BCNF, every nontrivial determinant must be powerful enough to identify an entire tuple.

Example: instructor and department information

Consider a relation containing:

  • Instructor ID

  • Instructor name

  • Salary

  • Department name

  • Building

  • Budget

Suppose the dependencies include:

  • Instructor ID →\to→ instructor name, salary, department name

  • Department name →\to→ building, budget

The second dependency violates BCNF in the combined relation: department name determines building and budget, but department name is not a superkey for the whole relation.

A decomposition separates the information into:

  • An instructor relation containing instructor ID, name, salary, and department name.

  • A department relation containing department name, building, and budget.

The instructor ID determines the other attributes in the instructor relation, and department name determines the other attributes in the department relation. Each nontrivial dependency in these relations has a superkey on its left side, so both are in BCNF.

General decomposition for a BCNF violation

For a violating dependency α→β\alpha \to \betaα→β, the standard decomposition creates:

  • R1=α∪βR_1 = \alpha \cup \betaR1​=α∪β

  • R2=R−(β−α)R_2 = R - (\beta - \alpha)R2​=R−(β−α)

Here, β−α\beta - \alphaβ−α means the attributes on the right side that are not already on the left. Those attributes are separated into R1R_1R1​, while the common determinant attributes remain in the other component.

The procedure is repeated on any resulting relation that still violates BCNF.


Lossless-join decomposition

A decomposition is lossless if the original relation can be reconstructed exactly by joining the decomposed relations. For every valid instance of the original schema, joining the corresponding component instances must produce precisely the original tuples—no missing information and no spurious combinations.

For a binary decomposition of RRR into R1R_1R1​ and R2R_2R2​:

  • Their attributes must cover the original schema: R1∪R2=RR_1 \cup R_2 = RR1​∪R2​=R.

  • The common attributes are R1∩R2R_1 \cap R_2R1​∩R2​.

  • Under the dependencies, the common attributes must functionally determine all attributes of at least one component. Equivalently, the common attributes must be a superkey of at least one component.

A common set that is a key in one component identifies at most one matching tuple there. This prevents the natural join from combining one tuple with multiple incompatible tuples and producing spurious results.

In the instructor–department decomposition, the common attribute is department name. It is a key of the department relation because it determines building and budget. The join can therefore recover department information for each instructor without introducing extra combinations.


Dependency preservation

A decomposition is dependency-preserving if the original dependencies can be checked using the decomposed relations, without first joining them back together.

This matters because checking a dependency by joining large relations can be expensive. A good design therefore aims to keep each dependency verifiable in one or more individual components. The instructor–department decomposition preserves the dependencies: the instructor ID dependency can be checked in the instructor relation, and the department-name dependency can be checked in the department relation.

BCNF does not always preserve dependencies

Consider a relation with attributes:

  • CCC: city

  • SSS: street

  • ZZZ: ZIP code

Suppose the dependencies are CS→ZCS \to ZCS→Z and Z→CZ \to CZ→C. The set CSCSCS is a key. The dependency CS→ZCS \to ZCS→Z satisfies BCNF because its left side is a key. However, Z→CZ \to CZ→C violates BCNF: ZZZ is not a superkey for the whole relation.

Decomposing on Z→CZ \to CZ→C gives:

  • R1(Z,C)R_1(Z,C)R1​(Z,C)

  • R2(S,Z)R_2(S,Z)R2​(S,Z)

The common attribute is ZZZ. In R1R_1R1​, ZZZ determines CCC and itself, so it is a key of that component. The decomposition is lossless.

However, the dependency CS→ZCS \to ZCS→Z involves all three attributes and cannot be checked in either component alone. Checking it requires joining the components to reconstruct the original relation. Thus, this decomposition is lossless but does not preserve all dependencies.

This example shows that BCNF guarantees neither dependency preservation in every decomposition nor the ability to check every original dependency locally.


Third normal form

Third Normal Form (3NF) relaxes BCNF in a way that can allow dependency preservation. For every dependency α→β\alpha \to \betaα→β in F+F^+F+, 3NF requires at least one of the following:

  • The dependency is trivial.

  • α\alphaα is a superkey.

  • Every attribute in β−α\beta - \alphaβ−α is part of at least one candidate key.

An attribute that belongs to at least one candidate key is called a prime attribute. Different attributes in β−α\beta - \alphaβ−α may belong to different candidate keys; they do not all have to belong to the same key.

Every BCNF relation satisfies 3NF, because it satisfies the first two conditions. The converse is not always true: 3NF permits some dependencies whose left side is not a superkey, provided the right-side attributes are prime. This relaxation helps retain dependencies during decomposition.


Goals and trade-offs in normalization

Normalization aims to organize relational schemas so that their structure represents information reliably and avoids unnecessary redundancy. When a schema is not adequately structured, it can be decomposed into smaller relations.

A desirable decomposition aims for:

  • Lossless reconstruction: The original information can be recovered exactly.

  • Dependency preservation: Constraints can be checked without expensive joins.

  • Reduced redundancy: Facts are stored in appropriate places rather than repeatedly.

  • Acceptable query cost: Common queries do not become unnecessarily expensive.

These goals can conflict. Decomposition can reduce redundancy and eliminate anomalies, but queries that previously used one relation may now require joins. Conversely, keeping information together may make some queries cheaper while creating repeated data and update problems. Schema design must balance the costs of redundancy, constraint checking, reconstruction, and query execution.


BCNF does not address every kind of redundancy

BCNF is based on functional dependencies, but not all problematic redundancy is caused by functional dependencies.

Suppose an instructor can have multiple children and multiple phone numbers, and these facts are independent of one another. A relation containing instructor ID, child name, and phone number may need one tuple for every child–phone combination. For instance, two children and two phone numbers may require four tuples even though the child facts and phone facts are independent.

This creates redundancy and anomalies:

  • Insertion anomaly: Adding one phone number may require multiple tuples because the instructor has multiple children.

  • Update anomaly: Changing a phone number may require updates to several tuples.

  • Unnecessary combinations: The relation records child–phone pairings even when the facts are independently associated with the instructor.

There may be no nontrivial functional dependency that captures these independent multiple-valued facts. The relation can therefore satisfy BCNF while still containing serious redundancy. Separating child information and phone information into their own relations can remove the repeated combinations. This kind of problem motivates higher normal forms, including Fourth Normal Form (4NF), which addresses multivalued dependencies rather than only functional dependencies.


Key takeaways

  • F+F^+F+ contains all functional dependencies implied by FFF; Armstrong’s axioms provide a sound and complete basis for deriving them.

  • The attribute closure α+\alpha^+α+ supports key identification and tests whether α→β\alpha \to \betaα→β follows from FFF.

  • BCNF requires every nontrivial dependency to have a superkey on the left.

  • A decomposition should be lossless so that joining its components recovers exactly the original information.

  • Dependency preservation allows constraints to be checked without reconstructing the original relation.

  • BCNF decomposition can be lossless yet fail to preserve dependencies.

  • 3NF allows a controlled relaxation of BCNF when right-side attributes are prime.

  • Functional-dependency-based normal forms do not eliminate every form of redundancy; independent multivalued facts can require higher normal forms.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent