lt10-fd (1)
-
Upload
haneesha-muddasani -
Category
Documents
-
view
218 -
download
0
Transcript of lt10-fd (1)
-
7/29/2019 lt10-fd (1)
1/26
-
7/29/2019 lt10-fd (1)
2/26
Database Systems &Applications
Lec 9Functional Dependencies
-
7/29/2019 lt10-fd (1)
3/26
Determinant
The attribute on the left-hand side ofthe arrow in a functionaldependency.
-
7/29/2019 lt10-fd (1)
4/26
Candidate (Primary) key
An attribute or combination of attributesthat uniquely identifies a row in a relation.It should satisfy
Unique identification. i.e., for every row, thevalue of the key must uniquely identify thatrow. This property implies that each nonkeyattribute is functionally dependent on the
candidate key. Nonredundancy : No attribute in the key (in the
case of multi-attribute key) can be deletedwithout destroying the property of uniqueidentification.
-
7/29/2019 lt10-fd (1)
5/26
Determinant vs Candidate key
Let us summarize the relationshipbetween determinants and candidatekeys. A candidate key is always a
determinant.
A determinant may or may not be a
candidate key.
-
7/29/2019 lt10-fd (1)
6/26
Examples
st_id st_name h_no r_no address
STUDENT1
STUDENT2
st_id c_no st_name h_no r_no address sem year grade
-
7/29/2019 lt10-fd (1)
7/26
Examples
Ex 1:In the example STUDENT1, theattribute st_id is a determinant
and also a candidate key.Becausest_id uniquely identifies theremaining (non key) attributes in
the relation STUDENT1.
-
7/29/2019 lt10-fd (1)
8/26
Examples (cont.)
From the above two examples, it isclear that
a candidate key is a determinant that
uniquely identifies the remaining(non key) attributes in a relation.
A determinant may be a candidate key (such as st_id in
STUDENT1)
Part of a composite candidate key (suchas st_id in STUDENT2).
-
7/29/2019 lt10-fd (1)
9/26
Examples (cont.)
Ex 2:
In the example STUDENT2, the
attribute st_id is a determinant butnot a candidate key. Becausest_id does not uniquely identify theremaining (non key) attributes in
the relation STUDENT2.
-
7/29/2019 lt10-fd (1)
10/26
Rules of FDs Assume W, X, Y, Z are sets of attributes of R.
If Y X then X Y (reflexivity) If X Y then ZX ZY (augmentation)
If X Y and Y Z then X Z (transitivity)
If X Y and X Z then X YZ (Union/Combining)
If X YZ then X Y and X Z(splitting/decomposition)
If W X and XY Z then WY Z
If XY ZY then XY Z
First three are known as Armstrongs Axioms
-
7/29/2019 lt10-fd (1)
11/26
Rules of FDs (cont.) Reflexivity:
If {B1,B2,.,Bj} {A1,A2,.,Ai} thenA1A2.Ai B1B2Bj.
Augmentation:
If A1A2.Ai B1B2Bj thenA1,A2,.,AiC1C2Ck B1B2BjC1C2Ck
for any set of attributes C1,C2,,Ck.
Transitivity:
If A1A2.Ai B1B2Bj and B1B2Bj C1C2Ck then A1A2.Ai C1C2Ck.
-
7/29/2019 lt10-fd (1)
12/26
Rules of FDs (cont.)
Union:
If A1A2.Ai B1B2Bj and
A1A2.Ai C1C2Ck then
A1A2.Ai B1B2BjC1C2Ck
Decomposition:
If A1A2.Ai B1B2BjC1C2Ck and
A1A2.Ai B1B2Bj then
A1A2.Ai B1B2BjC1C2Ck
-
7/29/2019 lt10-fd (1)
13/26
Rules of FDs (cont.)
If W X and XY Z then WY Z
If D1D2Dl A1A2.Ai and
A1A2Ai B1B2Bj C1C2Ck and
A1A2.Ai C1C2Ck
then D1D2Dl B1B2Bj C1C2Ck.
If XY ZY then XY Z
If A1A2Ai B1B2BjC1C2CkB1B2Bj
then A1A2.Ai B1B2Bj C1C2Ck.
-
7/29/2019 lt10-fd (1)
14/26
14
Trivial FunctionalDependencies
A1 A2 A3.A n B1 B2 B3 Bm is
Trivial if the Bs are a subset of the As.
Nontrivial if at least one of the Bs is notamong the As.
Completely nontrivial if none of the Bsalso one of the As.
-
7/29/2019 lt10-fd (1)
15/26
PILOT FLIGHT DATE DEPARTS
Soumini 83 9 Aug 10:15am
Soumini 116 10 Aug 1:25pm
Samulya 281 8 Aug 5:50pm
Samulya 301 12 Aug 6:35pm
Samulya 83 11 Aug 10:15am
Sekhar 83 13 Aug 10:15amSekhar 116 12 Aug 1:25pm
-
7/29/2019 lt10-fd (1)
16/26
PILOT FLIGHT DATE DEPARTS
Soumini 83 9 Aug 10:15am
Soumini 116 10 Aug 1:25pm
Samulya 281 8 Aug 5:50pm
Samulya
301 12 Aug 6:35pm
Samulya
83 11 Aug 10:15am
Sekhar 83 13 Aug 10:15a
mDEPARTS is determined by FLIGHT
-
7/29/2019 lt10-fd (1)
17/26
PILOT FLIGHT DATE DEPARTS
Soumini 83 9 Aug 10:15am
Soumini 116 10 Aug 1:25pm
Samulya 281 8 Aug 5:50pm
Samulya
301 12 Aug 6:35pm
Samulya
83 11 Aug 10:15am
Sekhar 83 13 Aug 10:15a
mPILOT is determined by FLIGHT, DATE
-
7/29/2019 lt10-fd (1)
18/26
FLIGHT DATE FLIGHT
FLIGHT DATE DATE
FLIGHT DATE
DEPARTS DATE
FLIGHT DEPARTS
FLIGHT DATE PILOT
Trivial
NonTrivial
Completely
Non Trivial
-
7/29/2019 lt10-fd (1)
19/26
Attribute closure
Suppose {A1,A2,.,An} is a set ofattributes and S is a set of FDs. The closureof {A1,A2,.,An} under the FDs in S is the
set of all attributes B such that everyrelation that satisfies all the FDs in set Salso satisfies A1,A2,.,An B. i.e., A1,A2,.,An follows from the FDs of S. It isdenoted as A1A2An by {A1,A2,,An}+.
-
7/29/2019 lt10-fd (1)
20/26
Attribute closure (Contd)
Starting with the given set ofattributes, we repeatedly expand the
set by adding the right sides of FDsas soon as we have included their leftsides. Eventually, we can not expandthe set any more and the resulting
set is the closure.
-
7/29/2019 lt10-fd (1)
21/26
Attribute closure (cont.) The following steps explain in more detail about the above:
step1. Let X be a set of attributes that eventually will
become the closure. First initialize X to {A1,A2,,An}.step2. Search for some FD B1B2Bm C such that all of
B1,B2,,Bm are in the set of attributes X, but not C.
Then add C to the set X.
step3. Repeat step 2 as many times as necessary until no
more attributes can be added to X. Since X can only grow
and number of attributes of any relation schema are finite,eventually nothing can be added to X.
step4. The set X, after no more attributes can be added to it is the
correct value of {A1,A2,,An}+.
-
7/29/2019 lt10-fd (1)
22/26
Attribute closure (Contd)
Let F be a set of FDs holding on a relationR. Let X, Y be sets of attributes of R. ThenY is said to be attribute closure of X,denoted by X+ = Y, if X Y follows from F
Algorithm
Ex: Find attribute closure of {A,B} w.r.tthe FDs:
AB C, BC AD, D E Useful to check whether a given FD follows from
given set of FDs: example AB D, D A Useful to check whether a given set of attributes
forms key w.r.t the FDs
Useful to find all FDs that hold on a relation
-
7/29/2019 lt10-fd (1)
23/26
Closure Test
An easier way to test is to computethe closure ofY, denoted Y+.
Basis: Y+ = Y.
Induction: Look for an FDs left sideXthat is a subset of the current Y+. Ifthe FD isX->A, addA to Y+.
-
7/29/2019 lt10-fd (1)
24/26
Attribute closure(example)
A relation has attributes
st_id, st_name, gender, dob, fname, hostel_no,room_no,
c_no,grade,sec_no,class_room
A = st_id, B=st_name,C=gender,
D=dob, E=fname, F=hostel_no,G=room_no, H=c_no, I=grade,J=sec_no,
K=class_room
The above relation has the FDs
AB CD, AH IJ, HJ K , A BE ,A F, AF G
Att ib t l ( l [ t ])
-
7/29/2019 lt10-fd (1)
25/26
Attribute closure (example[cont.]) The closure of {A,H} is {A,H}+.
Let X = {A,H}
These two attributes are on the left side of FD, AH IJ are in X, so add I,J to X,i.e., X= {A,H,I,J}.
In FD HJ K, the left side attributes H , J, form the subset of X, so add K to X,i.e., X={A,H,I,J,K}.
In FD A BE , the left side attributes A form subset of X, so add B,E to X, i.e.,X={A,B,E,H,I,J,K}.
In FD AB CD, the left side attributes A B form subset of X, so add C,D to X ,i.e.,X = {A,B,E,H,I,J,K,C,D}
In FD A F , the left side attributes A form subset of X, so add F to X, i.e.,X={A,B,C,D,E,F,H,I,J,K}.
In FD AF G , the left side attributes A form subset of X, so add G to X, i.e.,X={A,B,C,D,E,F,G,H,I,J,K}.
Therefore AH is the candidate key for the given relation.
-
7/29/2019 lt10-fd (1)
26/26
Is AH K ?