160 likes | 187 Views
Learn about functional dependence in databases, how attributes relate to each other, and discover examples and rules of functional dependencies.
E N D
Functional Dependence Lecture 11 Inst: Haya Sammaneh
Functional Dependence • Existence dependence: The existence of B depends on A • Functional dependence: B’s value depends on A’s 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 • Loan-info = (branch-name, loan-number, customer-name, amount)We expect the following set of functional dependencies to hold: loan-number amount loan-number branch-namebut would not expect the following to hold: loan-number customer-name
Examples loan-number amountloan-number branch-nameloan-number customer-name Another example: reverse of the fd’s above
Closure of a Set of Functional Dependencies • Given a set of functional dependencies F, there are certain other functional dependencies that are logically implied by F. • The set of all functional dependencies logically implied by F is the closure of F. • We denote the closure of F by F+. • We can find all of F+ by applying : • if , then (reflexivity) • if , then (augmentation) زياده • if and , then (transitivity)تعدي
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 Armstrong’s Axioms • We can find all of F+ by applying : • if , then (reflexivity)loan-no loan-no loan-no, amount loan-noloan-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 B A C CG H • CG I • B H} • some members of F+ • A H • AG I • CG HI A B; B H A C; AG CG; CG I
result contains all of the attributes of R, so stop Example • R = (A, B, C, G, H, I)F = ( A B A C CG H CG I B H} • (AG+)1. Result= AG2. 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
Example • R = (A, B, C, G, H, I)F = { A BA CCG HCG IB H} • some members of F + • A H • 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
Trivial and non trivial dependency • A Functional dependency A1,A2,….An Bn is said to be trivial dependency if B is one of A’s such as: • title, year title • Not trivial if one of B’s not on A’s such as: • title, year length, year • Complete not trivial dependency if all B’s not found on A’s
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