Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
237 views

Functional Dependency (DBMS)

Functional dependencies define constraints between attributes in a database relation. A functional dependency X → Y means that the values of attributes X uniquely determine the values of attributes Y. The closure of a set of functional dependencies F (written F+) includes all dependencies logically implied by F. To test if an attribute set is a superkey, we compute its closure - if the closure includes all attributes, then the set is a superkey.

Uploaded by

nikita
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
237 views

Functional Dependency (DBMS)

Functional dependencies define constraints between attributes in a database relation. A functional dependency X → Y means that the values of attributes X uniquely determine the values of attributes Y. The closure of a set of functional dependencies F (written F+) includes all dependencies logically implied by F. To test if an attribute set is a superkey, we compute its closure - if the closure includes all attributes, then the set is a superkey.

Uploaded by

nikita
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Functional

Dependency
1
What is Functional Dependency

•A functional dependency is defined as a constraint between two


sets of attributes in a relation from a database.

• A functional dependency allows us to express constraints that


uniquely identify the values of certain attributes.

• The value for a certain set of attributes determines uniquely


the value for another set of attributes.

• Key is a set of attributes that uniquely identified an entire tuple

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.

• These restrictions are examples of functional dependencies.


Informally, a functional dependency occurs when the values of
a tuple on one set of attributes uniquely determine the values
3
on another set of attributes.
Functional Dependency cont..
• Thus, given a tuple and the values of the attributes X, can
determine the corresponding value of the Y attributes.

• X is a set of attributes {one or more than one}


• Y is a set of attributes {one or more than one}

• Y is called dependent attribute and x is called determinant


attributes set.
• In other word we can say Y is Functionally dependent on X
• It represented by X Y

• Sometime relations are also evaluated against such a rules.


• Relations that satisfy all such constraints are called legal 4
relations.
Functional Dependency cont..
• Given a relation R,

If a set of attributes X in R is said to functionally determine


another attribute Y, (written X → Y) if and only if each X value
is associated with at most one Y value.

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

So consider Schema R, let   R ,  R the functional


dependency  -> holds on R if ,for all pairs of tuples t1 and t2
In R such that, t1[ ] = t2[ ] it is also the case that t1[  ]= t2 [  ]

• Here x->y is true on relation R but x->z in not hold on relation 6


R.
• What about y -> x ?
Functional Dependency cont..
• Back to flight example Our restrictions can be phrased as

1. TIME functionally depends on FLIGHT,


2. FLIGHT functionally depends on {PILOT, DATE, TIME}, and
3. PILOT functionally depends on {FLIGHT, DATE}.

FLIGHT -> TIME


{PILOT, DATE, TIME} -> FLIGHT
{FLIGHT, DATE} -> PILOT

7
Functional Dependency cont..

PILOT FLIGHT DATE DEPARTs


X 83 9 Aug 10: 15a
X 116 10 Aug 1:25 P
Y 281 8 Aug 5:50 A
Y 301 12 Aug 6:36 P
Y 83 11 Aug 10:15 A
Z 83 13 Aug 10:15 A
Z 116 12 Aug 1:25 P
W 281 9 Aug 5:50 A
W 281 13 Aug 5:50 A
W 412 15 Aug 1:25 P

8
Functional Dependency cont..

Trivial Function Dependency.

• Some functional dependency are trivial in nature, b’coz they


are’ satisfied by all relations.

• If Relation R having attribute A the A-> A is satisfied at all.

• In general a functional dependency of the form S -> T is trivial


if T  S.

9
Closure of functional dependency F

• Given a set of functional dependency F hold on Relation R ,

• Closure of F is denoted by F+ , and it is a set of all functional


dependency that can be inferred given the set F(set of all FDs
logically implied by F).

• That means it may be possible to infer that certain other


functional dependency must hold on the relation R.

• For example if FD A->B and B->C hold on relation R then


we can infer the functional dependency A-> C must be hold on
R.
• We can say A->C is logically implied by set of FDs (A->B,B- 10
>C) on Relation R.
Closure of functional dependency F

• How to Compute Closure F+

• To find the closure of FD set F we can use Axioms in other


words Rules of Inference.
• Developed by Armstrong in 1974, there are six rules (axioms)
• By applying these rules repeatedly we can find 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)

Closure of Set F is {A->BC,A->H,CG->IH} so on… 13


Example 2

R={A,B,C,G,H,I}
F = SET OF FUNCTIONAL DEPENDECIES HOLD BY R
{ A->B ,A->C,CG->H,H ->I}

• Prove: AG-> I hold on Relation R


• Steps:
• 1. A->C (given)
• 2.CG->H (given)
• 3. AG-> H ( acc. to Pseudo Transitivity rule)
• 4.H-> I (given)
• 5.AG -> I (Transitivity Rule) ---Proved

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

You might also like