Functional Dependency (DBMS)
Functional Dependency (DBMS)
Dependency
1
What is Functional Dependency
2
• Functional dependency allows us to express constraints that
we can not express with superkey.
How to Define Functional Dependency
• Consider the relation R: {PILOT FLIGHT DATE,DEPARTS).
• Each tuple indicate which pilot flies a given flight on a given
day, and what time the flight leaves. Not every combination of
pilots, flights, dates and times is allowable in assign.
•
• The following restrictions apply, among others.
1. For each flight there is exactly one time.
2. For any given pilot, date, and time, there is only one flight.
3. For a given flight and date, there is only one pilot.
Example:
X Y Z
A1 B1 C1
A2 B2 C1
A3 B3 C2
• Which of the followings are true ???
• x -> y , x -> z ,y -> z, y -> x, z->y, z-> x 5
Functional Dependency cont..
Example 2: X Y Z
A1 B1 C1
A1 B1 C1
A2 B3 C2
A2 B3 C3
A3 B3 C2
7
Functional Dependency cont..
8
Functional Dependency cont..
9
Closure of functional dependency F
1. Reflexivity Rule
If X is a set of attributes and Y is a subset of X, then X Y holds.
2. Augmentation Rule
11
If X Y holds and W is a set of attributes, then WX WY
holds.
Closure of functional dependency F
3. Transitivity Rule
If X Y and Y Z holds, then X Z holds.
4. Union Rule
If X Y and X Z holds, then X YZ holds.
5. Decomposition Rule
If X YZ holds, then so do X Y and X Z.
6. Pseudo transitivity Rule
If X Y and WY Z hold then so does WX Z.
• a-.j hj- >d ha->d
• These Rules are applied repeatedly in order to find complete
set of Closure of given set of functional dependency F hold by
relation R.
12
Closure of functional dependency F
Example:
R={A,B,C,G,H,I}
F = SET OF FUNCTIONAL DEPENDECIES HOLD BY R
{ A->B ,A->C,CG->I,CG->H,B->H}
HERE,
1. A->B ,A->C so A->BC hold on R(Union rule)
2. A->B, B->H so A->H (tr.Rule)
3. CG->I and CG->H so CG->IH hold on R(union rule)
R={A,B,C,G,H,I}
F = SET OF FUNCTIONAL DEPENDECIES HOLD BY R
{ A->B ,A->C,CG->H,H ->I}
14
Closure of Attribute sets
• Let be set of attribute in Relation R {A,B,C,G,H,I}.
• If -> C then we can say that Attribute C is functionally
determined by .
• To test whether a set is a SuperKey in relation R. we
compute the closure of Attribute set denoted as + .
• If Closure contains all the attributes or relation R then we can
say that set can be a Super key of relation R.
• To compute closure of attribute set , we take in to account
given set of Functional Dependency F.
• Algorithm: ( to test can be a super key or not)
1. Result :=
2. While (change in Result) do
for each FD of the form -> do
if Result then 15
Result:= Result U (add to result)
Closure of Attribute sets
• 3. end
• 4. check if Result contain all the Attributes of Schema R then
• is super key otherwise not a super key.
• Example:
• R={A,B,C,D}
• Set F= {A->B,B->CD}
• Prove A can be a super Key in Relation R.
• Here set ={A}
• So following the algorithm to find + or (A)+ .
• 1. Result ={A}
• (in while loop)
• here A->B hold on R and A Result so add B to Result
• so Result = {AB} 16
• take B->CD and B Result so add CD to Result
Closure of Attribute sets
• so Result:= {ABCD}
• Now no more FD left in Set F or no more change is possible in
Result so while loop end here
• Now check is Result contain all the Attributes of Schema R
• here Result={ABCD} means (A)+ ={ABCD} yes it is.
• So we can say that A be Super key of R
• Example 2:
• R={A,B,C,G,H,I}
• Set F ={A->B,A->C,CG->I,CG->H,B-> H}
• Compute (AG)+ and check AG is super key or not ??/
17