1. Gyanastra
  2. Database Systems
  3. Functional Dependencies
  4. Functional Dependency and Its Relation to Keys
Free lesson, no account needed 8 min read 10 practice questions after it
Asked in past papers10 times
  • GATE CSE20162014200520022000
  • ISRO2011
  • UGC NET2019201720092008

Database Systems · Functional Dependencies

Functional Dependency and Its Relation to Keys

Overview

Functional dependencies (FDs) and candidate keys are the tools used to formally evaluate whether a database design is good or bad. "Formally" means there is a well-defined procedure; if the design turns out to be bad, algorithms use these FDs as the basis for dividing (decomposing) the tables.
Once FDs are understood, the next step is normalization.

Key concepts

  • Functional dependency (FD): Given the value of A, you will be able to identify B and C uniquely.
    This is the key idea generalized: a key is a special case of a functional dependency, but a functional dependency need not be a key.
  • Key (candidate key or super key): Whenever an attribute is called a "key", the term means either a candidate key or a super key. Its meaning: given the value of that attribute, a row of the table can be identified uniquely.
    If A is a key and A takes the value 2, then from that value 2 the values of the other attributes (B, C, ...) in that row can be found.
  • A determines B: Given any value of A, querying the value of B always returns the same answer — in any tuple of the relation, it does not matter which tuple is looked at.
  • Repeated left-hand values are allowed: In an FD, the value of A may repeat across many tuples, provided the B value is the same every time.
  • Use in design: FDs plus candidate keys give a formal procedure to judge a design; if it is bad, algorithms use the FDs to split the tables (normalization).

How it works

  1. Informal statement. If any value of A is given, it must be possible to say uniquely what the values of B and C are for that value.
    For example, if A = 2, the corresponding B and C values can be stated (as a pair such as (B, C) or (A, B)).
  2. Formal (tuple-based) statement. Let T1 and T2 be two tuples of the relation, where T1(A) means the value that tuple T1 has in attribute A. If T1(A) = T2(A) — two tuples happen to have the same value in attribute A — then the B and C values of T1 and T2 must also be the same.
  3. Same statement in words. Wherever A repeats, the corresponding B and C values must also repeat (be the same). Equivalently: given a value of A, the value of B should be determinable.
  4. Relation between a key and an FD. If A determines B, then A need not be a key. The only meaning of A → B is: whatever the value of A is, a unique value of B can be obtained.
  5. Meaning of "A determines B". Given any value of A, querying the value of B always gives the same answer — here or there (in any tuple of the relation), it does not matter which tuple is looked at.
  6. Why it matters for splitting tables. The FD concept is the basis for decomposing tables during normalization.

Formulas

  • A→BA \to B holds if and only if, for every pair of tuples T1, T2 in r: T1(A)=T2(A)⇒T1(B)=T2(B)T1(A) = T2(A) \Rightarrow T1(B) = T2(B)

  • T1, T2 = any two tuples of the relation

  • T1(A) = value of tuple T1 in attribute set A

  • ⇒\Rightarrow = "implies"; whenever the left side holds, the right side must hold

  • General form for a set of attributes BC: A→BCA \to BC holds iff T1(A)=T2(A)⇒T1(B)=T2(B)T1(A) = T2(A) \Rightarrow T1(B) = T2(B) and T1(C)=T2(C)T1(C) = T2(C).

  • Key as a special case: A is a (candidate) key of r if A→A \to (all attributes of r), and no proper subset of A has this property (for a candidate key).

Worked examples

Example 1 (key ⇒ FD). Let A be a candidate key of a relation with attributes A, B, C.

  • Given A = 2, the row can be located uniquely.
  • Therefore the corresponding B and C values can be read off.
  • Hence A → B and A → C, i.e. A → BC.

Example 2 (formal check using two tuples). Suppose T1(A) = 2 and T2(A) = 2 (A has the same value in two different tuples).

  • If A → BC holds, then T1(B) must equal T2(B) and T1(C) must equal T2(C).
  • If the B or C values differed between T1 and T2, the FD A → BC would be violated.

Example 3 (FD without key). Columns A and B with rows:

AB
a1
a1
b2
b2
  • Check A → B: every tuple with A = a has B = 1; every tuple with A = b has B = 2. The condition is satisfied, so A → B holds.
  • A is not a key here, since the value a occurs in more than one row (it does not identify a row uniquely).
  • Conclusion: a functional dependency can exist on an attribute that is not a key.

Comparison

AspectKey (candidate key / super key)Functional dependency A → B
MeaningGiven the value of the attribute, a row of the table is identified uniquelyGiven the value of A, the value of B is determined uniquely
Number of attributes determinedAll attributes of the relationOnly the attributes on the right side (e.g. B, or B and C)
Uniqueness of the left sideLeft side value cannot repeat across two different rowsLeft side value may repeat in many tuples, provided the right side value is the same every time
ScopeSpecial case of an FD (A → all attributes)More general; need not be a key
UseIdentifies tuplesFormally evaluates a design and drives table decomposition (normalization)

Revision summary

  • FDs plus candidate keys give a formal procedure to judge whether a design is good; if not, algorithms use the FDs to split the tables (normalization).
  • The word "key" always means candidate key or super key: given its value, one row is identified uniquely, hence all other attribute values of that row can be found.
  • Functional dependency = generalized key idea: the value of A lets you uniquely know the value of B (and C, ...).
  • Formal test with two tuples: if T1(A) = T2(A) then T1(B) = T2(B) (and T1(C) = T2(C)) must also hold.
  • Equivalent phrasing: wherever A repeats, B and C must repeat the same value.
  • A determines B does not imply A is a key. A → B only says the value of A yields a unique value of B.
  • Repeated A values are allowed in an FD — (a,1), (a,1), (b,2), (b,2) — A → B still holds although A is not a key.
  • For any value of A, querying B always returns the same answer in every tuple — that is the meaning of "A determines B".

Previous-year exam insights

  • A superkey is any set of attributes that uniquely identifies a tuple; a candidate key is a minimal superkey (no proper subset is a superkey); a primary key is one chosen candidate key.
    Hence primary key ⊆ candidate key ⊆ superkey.
    Asked inUGC NET 2017UGC NET 2019GATE 2016UGC NET 2008
  • A prime attribute is an attribute that belongs to at least one candidate key; a non-prime attribute belongs to no candidate key.
    Asked inGATE 2014
  • An FD X → Y is violated by an instance only if two tuples agree on all attributes of X but disagree on some attribute of Y; if no two tuples agree on X, the FD holds vacuously.
    Asked inGATE 2002GATE 2000GATE 2014
  • Armstrong's axioms are the three sound and complete inference rules: reflexivity (if Y ⊆ X then X → Y), augmentation (if X → Y then XZ → YZ), and transitivity (if X → Y and Y → Z then X → Z).
    Asked inISRO 2011
  • A set of attributes is a superkey of a relation if its closure under the given FDs contains all attributes of the relation; it is a candidate key if it is a superkey and no proper subset of it is a superkey.
    Asked inGATE 2016
  • In an FD X → Y, X is called the determinant (the left-hand side); a candidate key is a determinant that determines all attributes and is minimal.
    Asked inUGC NET 2009
Pages 1–2 of 2