Functional Depencies
Functional Depencies
Introduction
Formal tool for analysis of relational schemas
Caption
Caption
Caption
F Closure - F +
• Typically, the schema designer specifies the functional dependencies that are
semantically obvious; usually, however, numerous other functional
dependencies hold in all legal relation instances among sets of attributes that
can be derived from and satisfy the dependencies in F. Those other
dependencies can be inferred or deduced from the FDs in F
• F = {Ssn -> {Ename, Bdate, Address, Dnumber}, Dnumber -> {Dname, Dmgr_ssn}}
Caption
• Ssn -> {Name, Dmgr_ssn}
• Ssn -> Ssn
• Dnumber -> Dnumber
• Definition. Formally, the set of all dependencies that include F as well as all
dependencies that can be inferred from F is called the closure of F; it is
denoted by F+.
• We use the notation F |=X -> Y to denote that the functional dependency X-
>Y is inferred from the set of functional dependencies F.
Inference rule IR1 through IR6
• Suppose that X → Y and that two tuples t1, and t2 exist in some relation
instance r of R such that t1[X] = t2[X].
1. X → YZ (given).
1. X → Y (given).
2. X → Z (given).
1. X →Y (given).
2. WY → Z (given).
• Inference rules IR1 through IR3 are known as Armstrong's inference rules.
• It has been shown by Armstrong (1974) that inference rules IR1 through IR3 are
sound and complete.
• By sound, we mean that given a set of functional dependencies F specified on a
relation schema R, any dependency that we can infer from F using IR1 through
IR3 holds in every relation state r of R that satisfies the dependencies in F.
• By complete, we mean that using IR1 through IR3 repeatedly to infer
dependencies until no more dependencies can be inferred results in the
complete set of all possible dependencies that can be inferred from F.
X Closure (X+)
repeat
oldX+ := X+;
B+ = {B,C,A,D,E}
Equivalence of Sets of Functional Dependencies
• R(ABC)
• F={A->B, B->C, C->A}
• G={C->B, B->A, A->C}
• Given below are two sets of FDs for a relation R(A,B,C,D,E). Are they
equivalent?
• R(ABC)
• F={A->B, AB->C}
• A+ = {ABC}
• Since A+ is {ABC} we can simplify functional dependency F as
E={A->B, B->C}
• Informally, a minimal cover of a set of functional
dependencies E is a set of functional dependencies F
that satisfies the property that every dependency in E is
in the closure F+ of F.
Example-2
• R(ABC)
• F={A->B, B->C, A->C}
• A+ = {ABC}
• B+ = {BC}
• Minimal FD
• E={A->B, B->C}
A functional dependency F is said to be minimal if it satisfies the
following conditions:
1. Every dependency in F has a single attribute for its right-hand side.
2. We cannot replace any dependency X->A in F with a dependency Y->A,
where Y is a proper subset of X, and still have a set of dependencies that
is a equivalent to F.
3. We cannot remove any dependency from F and still have a set of
dependencies that is equivalent to F.
• Simplified definition
1. Single attribute on the RHS of the FD.
2. No extraneous LHS attribute. (Example-1)
3. No redundant FDs. (Example-2)
Minimal Cover - Example
• R(ABCDE)
• F={A->D, BC->AD, C->B, E->A, E->D}
• Step-1
• F={A->D, BC->A, BC->D, C->B, E->A, E->D}
• Step-2
• For FD BC->A [B+= B, C+=CBAD] – Eliminate B from LHS
• F={A->D, C->A, BC->D, C->B, E->A, E->D}
• For FD BC->D [B+= B, C+=CBAD]
• F={A->D, C->A, C->D, C->B, E->A, E->D}
• Step-3
• F={A->D, C->A, C->B, E->A}
Exercises
1. Given FD E={B->A,D->A, AB->D}. Find the minimum cover.
2. Is the set of functional depencies G= {Ssn-> {Ename, Bdate,
Address, Dumber}, Dnumber -> {Dname, Dmgr_ssn}} minimal? fI
not, try to find a minimal set of functional dependencies that is
equivalent to G. Prove that your set is equivalent to G.
3. A set fo FDs for the relation R(A, B, C, D, E, F) is AB->C, C-> A, BC
-> D, ACD->B, BE->C, EC->FA, CF -> BD, D->E. Find a minimum
cover for this set of FDs.
Using FDs to determine Keys
• Prime attributes
• An attribute is a prime attribute if it is part of any key.
• Non-Prime attributes
• An attribute is a non-prime attribute if it is not part of any key.
Example
1. R(ABC)
• F={A->B, B->C} – ANS: Key A, PRIME – A and Non-Prime - BC
2. R(ABCD)
• F={AB->C, C->B, C->D} – ANS: Key AB, AC
Prime – ABC, Non-prime - D
3. R(ABC)
• F={A->B, B->C, C->A} – ANS: Key A, B, C
Prime – ABC, Non-prime - NIL
Normalization of Relations
• Second normal form (2NF) is based on the concept of full functional dependency.
A functional dependency X → Y is a full functional dependency if removal of any
attribute A from X means that the dependency does not hold any more.
• A functional dependency X → Y is a partial dependency if some attribute A ε X can
be removed from X and the dependency still holds;
2NF decomposition
3NF decomposition
Points to be noted
• R(ABC)
• F={AB->C, C->A} Key – AB, BC, Prime=A,B,C
This relation is in 3NF but not in BCNF because of FD C->A, [C is not a SK]
Prove that any relation schema with two attributes is in BCNF
• Consider a relation schema R=(A, B) with two attributes. The only possible (non-
trivial) FDs are {A} ->{B} and {B} ->{A}. There are four possible cases:
1. No FD holds in R. In this case, the key is {A, B} and the relation satisfies BCNF.
2. Only {A} ->{B} holds. In this case, the key is {A} and the relation satisfies BCNF.
3. Only {B} ->{A} holds. In this case, the key is {B} and the relation satisfies BCNF.
4. Both {A} ->{B} and {B} ->{A} hold. In this case, there are two keys {A} and {B} and
the relation satisfies BCNF.
• R1(AB) R2(BC) A B B C
a1 b1 b1 c1
a2 b1
b2 c2
a3 b2
Exercises
1. R(ABCD). F={AB->CD, C->A, D->B}
All attribute are prime attribute. Therefore, this relation is in 2NF as well as
3NF.
Highest NF is 1NF
3. R(ABCDE). F={AB->CDE, D->BE}. CANDIDATE KEY: AB, AD
AB->CDE D->BE
BCNF Y N
3NF Y N
2NF Y N
4. R(ABCDE) F={A->BCDE, BC->ACE, D->E}
CANDIDATE KEY- A, BC. Prime – ABC, Non-Prime-DE
R11(AB), R12(BC),
Relation R11, R12, R2 are in 3NF
Convert the relation to 2NF and 3NF