Functional Dependencey: J.C.Patni
Functional Dependencey: J.C.Patni
J.C.PATNI
Functional Dependence
Existence dependence: The existence of B depends on A
Functional dependence: Bs value depends on As value
EmpName is functionally dependent on EmpNo
Given the EmpNo, I can one and only one value of
EmpName
Require that the value for a certain set of attributes
determines uniquely the value for another set of attributes.
Functional dependence is a generalization of the notion of
a key.
Functional Dependencies
Examples
loan-number amount
loan-number branch-name
customer-name
loan-number
Another example:
reverse of the fds above
loan-info
branch-nm
Perryridge
Perryridge
Perryridge
Wanchai
loan-info
branch-nm
Perryridge
Perryridge
Central
Wanchai
loan-no
L-001
L-001
L-001
L-002
loan-no
L-001
L-001
L-001
L-002
cust-nm
Peter Yeung
David Chan
May Chan
Leon Lai
cust-nm
Peter Yeung
Peter Yeung
Peter Yeung
Leon Lai
amount
100000
100000
100000
100000
amount
100000
100000
250000
100000
Closure
We can further simplify computation of F+ by
using the following additional rules.
If holds and holds, then
holds (union)
If holds, then holds and
holds (decomposition)
If holds and holds, then
holds (pseudotransitivity)
Examples of Armstrongs
Axioms
We can find all of F+ by applying :
if , then (reflexivity)
loan-no loan-no
loan-no, amount loan-no
loan-no, amount amount
if , then (augmentation)
loan-no amount
(given)
loan-no, branch-name amount, branch-name
if and , then (transitivity)
loan-no branch-name (given)
branch-name branch-city
(given)
loan-no branch-city
Example
R = (A, B, C, G, H, I)
F = {A
A
CG
CG
B
B
C
H
I
H}
some members of F+
A H
AG I
CG HI
A B; B H
A C; AG CG; CG I
Example
R = (A, B, C, G, H, I)
F= ( A B
A C
CG H
CG I
B H}
(AG+)
1. Result= AG
2. Result= ABCG (A C; A B and A
AG)
3. Result= ABCGH (CG H and CG AGBC)
4. Result=ABCGHI (CG I and CG
AGBCH)
Is AG a candidate key?
1. AG R
result contains
all of the
attributes of R,
so stop
Example
R = (A, B, C, G, H, I)
F={ AB
AC
CG H
CG I
B H}
some members of F +
AH
by transitivity from A B and B H
AG I
by augmenting A C with G, to get AG CG
and then transitivity with CG I
CG HI
from CG H and CG I : union rule
Example
Given this FD for this R(A,B,C,D,E,F)
AB C
AD E
BD
AFB
Check if AB+ is a key for this relation?
AB+ is key if AB+ can find all the attribute of R
ABAB
BD so B AB AB+ABD
ADE so AD ABDAB+ABDE
ABC so AB ABDE AB+ABCDE
AFB so AF Not ABDE AB+ABCDE
AB not a key because it does not contain all attributes such as F
Example
Given this FD for this R(A,B,C,D,E,F)
AB C
AD E
BD
AFB
Check if AF+ is a key for this relation?
AF is a key
Example
Given this FD for this R(A,B,C,D,E,F,G)
A D
D CG
BE
EF
ABF
What are all the keys for this relation?
Solution: we look to the right side of FD and take all the attribute
which does not found in the FD
Here is AB
Then find AB+ = ABCDEFG AB is a key
Example
Given this FD for this R(A,B,C,D)
AB C
CD
DA
What are all the keys for this relation?
Look to the right B
Take all minimum combination with B
AB,BC,BD
Find
AB+=ABCD
BC+=ABCD
BD+=ABCD
ALL AB,BC,BD are keys
List all the super keys for R that are not key (not minimal number of attributes)
ABC
BCD
ABCD
Example
Given this FD for this R(A,B,C,D)
AC D
completely non trivial
BC A
completely non trivial
DB
completely non trivial
What are the keys?
Look to right C take all combinations AC, BC, CD
What are the super key?
ABC
ADC
BCD
ABCD
ABD not a super key because C must be found on left side