You are on page 1of 30

Functional Dependence
 In a relation including attribute A and B, B is
functional dependent on A if, for every valid
occurrence, the value A determines the value B
 If B is ‘Functional Dependent on’ A, then A ‘is the
determinant of B’
 All fields are functionally dependent on the primary key –
or indeed any candidate key – be definition.

Example: Functional Dependency

Examples loan-number  amount loan-number  branch-name loan-number   customer-name loan-info branch-nm loan-no cust-nm amount Perryridge L-001 Peter Yeung 100000 Perryridge L-001 David Chan 100000 Perryridge L-001 May Chan 100000 Wanchai L-002 Leon Lai 100000 .

Functional Dependency Compound Determinants: If more than one attribute is necessary to determine another attribute in an entity. line#)  qty A002 002 20 800 (Order#. Example: order# line# qty price Full Functional Dependencies A001 001 10 200 A002 001 20 400 (Order#. Full Functional Dependency: Only of relevance with composite determinants. This is the situation when it is necessary to use all the attributes of the composite determinant to identify its object uniquely. then such a determinant is termed a composite determinant. line#)  price A004 001 15 300 .

unit#)  grade 9900100 A01 TH224 2 9900010 A01 TH224 14 9901011 A02 JS075 3 Partial Functional Dependencies 9900001 A01 TH224 16 unit#  room Repetition of data! . Functional Dependency Partial Functional Dependency: This is the situation that exists if it is necessary to only use a subset of the attributes of the composite determinant to identify its object uniquely. Example: Full Functional Dependencies student# unit# room grade (student#.

PLOCATION}  Employee SSN and project number determines the hours per week that the employee works on the project {SSN.Examples of FD constraints  Social Security Number determines employee name SSN  ENAME  Project Number determines project name and location PNUMBER  {PNAME. PNUMBER}  HOURS .

length is nontrivial but not completely nontrivial. Trivial Dependencies • A functional dependency A1A2…AnB is said to be trivial if B is one of A’s. year  year . . – For example: title. • Thus title. – Completely nontrivial if none of the B’s is also one of the A’s. year title is a trivial dependency. • We say that a dependency A1A2…AnB1B2…Bm is: – Trivial if the B’s are subset of A’s. – Nontrivial if at least one of the B’s is not among the A’s.

a candidate key is always a determinant. .Keys A functional dependency allows us to express constraints that uniquely identify the values of certain attributes. but a determinant doesn’t need to be a key. Whereas a key is a set of attributes that uniquely identifies an entire tuple. However.

 The closure of F (usually written as F+) is the set of all functional dependencies that may be logically derived from F. the closure.Closure  Let a relation R have some functional dependencies F specified.  F+.  Often F is the set of most obvious and important functional dependencies. is the set of all the functional dependencies including F and those that can be deduced from F. .

.  There are six rules (axioms).Axioms  To determine closure of the relation we need to learn some rules. using these RULES all possible functional dependencies may be derived.  Developed by Armstrong in 1974.

3. then X  Z holds. then WX  WY holds. each subset of X is functionally dependent on X. then X  Y holds.Armstrong’s Axioms 1. Reflexivity Rule : If X is a set of attributes and Y is a subset of X. . 2. Transitivity Rule : If X  Y and Y  Z holds. Augmentation Rule : If X  Y holds and W is a set of attributes.

Union Rule : If X  Y and X  Z holds. 5. then so do X  Y and X  Z.Derived Theorems from Armstrong’s Axioms 4. then X  YZ holds. Decomposition Rule : If X  YZ holds. 6. Pseudotransitivity Rule : If X  Y and WY  Z hold then so does WX  Z. .

amount  amount  if X  Y. branch-name  amount. then X  Y (reflexivity) loan-no  loan-no loan-no. amount  loan-no loan-no. then X  Z (transitivity) loan-no  branch-name (given) branch-name  branch-city (given) loan-no  branch-city .Examples of Armstrong’s Axioms  We can find all of F+ by applying :  if Y  X. branch-name  if X  Y and Y  Z . then WX  WY (augmentation) loan-no  amount (given) loan-no.

G.Example: Closure of set F of functional dependencies  R = (A. to get AG  CG and then transitivity with CG  I  CG  HI  from CG  H and CG  I : “union rule” . B. H. I) F= { AB AC GIVEN CG  H CG  I BH }  Find Closure of F: some members of F +  AH by transitivity from A  B and B  H   AG  I  by augmenting A  C with G. C.

etc. E). D → D. BD → D. transitive) Also. A →BC CD →E B→ D E→ A Solution: A → BC. C. B. we have (reflexive) A → ABCDE from the above steps (union) Since E → A. . A → E (union. BC → ABCDE (augmentative. Example: Compute the closure of the following set F of functional dependencies for relation schema R = (A. (decomposition) A → B and B → D  A → D (transitive) A → CD and CD → E. decomposition. C → C. we can conclude: A → B and A → C. D. transitive) A → A. CD → ABCDE (transitive) Since B → D and BC → CD. E → ABCDE (transitive) Since CD → E.

and the number of attributes is finite. but C is not.Algorithm • Starting with the given set of attributes. 3 Repeat step 2 as many times as necessary until no more attributes can be added to X. eventually nothing more can be added to X. An}. 4 The set X after no more attributes can be added to it is the: {A1. . A2. We then add C to X. An}+. First we initialize X to be {A1. repeatedly expand the set by adding the right sides of FD’s as soon as we have included their left sides. • Eventually. we cannot expand the set any more. A2. 1 Let X be a set of attributes that eventually will become the closure. 2 Now. …. repeatedly search for some FD in S: B1B2…BmC such that all of B’s are in the set X. …. Computing the Closure of Attributes . Since X can only grow. and the Xing set is the closure.

B. X  ABC  X  ABCD (UNION) – X = {A. CFB. X C  X ABC (UNION) – X = {A. • The FD: CFB cannot be used because its left side is never contained in X.D} Use: DE  ABCD ACDE (Augment ABC) X ABCE (Transitivity) X ABCDE (UNION) – X = {A.D. DE.C} Since: BCAD  ABC AD (Augment A) Since: X  ABC. ABC  AD X AD (Transitivity) X  AD.B.B}+? ABC. . BCAD.• What is {A.C. ABC  X C (Transitivity) Since : X AB.B}+.B.B} Since: X AB .C.E} No more changes to X are possible so X = {A. Solution: – X = {A.

Given this FD for this R(A.C.F) AB C AD E BD AFB Check if AB+ is a key for this relation? AB+ is key if AB+ can find all the attribute of R Solution: ABAB BD so B AB  AB+ABD ADE so AD ABDAB+ABDE ABC so AB ABDE AB+ABCDE AFB so AF Not ABDE  AB+ABCDE AB not a key because it does not contain all attributes such as F .E.D. Example QUES.B.

I) F={ AB AC CG  H CG  I B  H}  (AG) + ?  1. G. H. X = AG 2. It is a super key. C.  YES. X = ABCGH (CG  H and CG  AGBC) 4.  2. (G+) = G. (A+) = BC. X = ABCGHI (CG  I and CG  AGBCH  Is (AG) a candidate key ?  1. B. X = ABCG (A  C and A  B) 3. .Example  R = (A.

Computing the Closure of Attributes (Continued) • Example. Consider the previous example. Initially we have X={D}.E}.E} = {A.C. we have reached the closure. On the other hand consider testing the FD: DA.D.B}+. Suppose we want to test whether ABD follows from the set of the dependencies. – Concluding DA does not follow from the given set of dependencies. – First compute {D}+.E} and A  {D}+. Yes! Since D{A. .B. But here we are stuck. – So {D}+ = {D. Then we can use the given DE and X becomes {D.

if G+ subset-of F+)  F and G are equivalent if F covers G and G covers F  There is an algorithm for checking equivalence of sets of FDs .Equivalence of Sets of FDs  Two sets of FDs F and G are equivalent if:  Every FD in F can be inferred from G.e. F and G are equivalent if F+ =G+  Definition (Covers):  F covers G if every FD in G can be inferred from F  (i.. and  Every FD in G can be inferred from F  Hence.

Example:  R(ABC)  F= { A B. G+  Calculate F  G+  Calculate G  F+ . B A. A C}  First find closure F+ . B C. C A}  G={C B.

Example  F=(ABC.CDE}  G={ABCE. C D E } Find if F and G are equivalent?  G ‘= {A  BCDE} Find if F and G’ are equivalent? . AD. A A B D.

2.Minimal Sets of FDs  A set of FDs is minimal if it satisfies the following conditions: 1. 3. . We cannot replace any dependency X -> A in F with a dependency Y -> A. We cannot remove any dependency from F and have a set of dependencies that is equivalent to F. where Y proper-subset-of X ( Y subset-of X) and still have a set of dependencies that is equivalent to F. Every dependency in F has a single attribute for its RHS.

 “Extraneous”: Are there any attributes in A or B that can be safely removed ?  Without changing the closure implied by F  Example: Given F = {A  C. AB  C}  B is extraneous in AB  C since AB  C can be inferred even after deleting B . A  B.Extraneous Attributes  Consider F. and a functional dependency.

g. B  C. A  CD} can be simplified to {A  B. B  C. B  C. AC  D} can be simplified to {A  B.g. B  C. on LHS: {A  B. B  C. A  D} . A  C}  Parts of a functional dependency may be redundant  E. A  D}  E.Minimal Means:  No redundant functional dependencies!  Sets of functional dependencies may have redundant dependencies that can be inferred from the others  Eg: A  C is redundant in: {A  B. on RHS: {A  B.

H. E A} .E D} STEP 1: SINGLE ATTRIBUTE ON R.C B.EXAMPLE:  R(ABCDE) F{ A D . E A.S STEP 2: NO EXTRANEOUS ATTRIBUTE ON L. BC AD .H.S STEP 3: ELIMINATE REDUNDANT FDs Final Minimal Set: { A D. C B.C A.

ACDF→E. ABCD→E. ABCD→E.Algorithms  Example:  {A→B. ACDF→EG}  Make RHS a single attribute:  {A→B. ACDF→G}  Minimize LHS: ACD→E instead of ABCD→E  Eliminate redundant FDs  Can ACDF→G be removed?  Can ACDF→E be removed?  Final answer: {A→B. ACD→E. EF→GH. EF→H. EF→G. EF→H} . EF→G.

B  C. A  B. AB  C} ? { A  C. AB  C}  Is A is extraneous in AB  C  {A  B. B  C. B  C. B  C. AB  C} Yes  Set is now {A  B. B  C} . AB  C} ? {A  B. B  C} Yes  Set is now {A  B. B  C}  The canonical cover is: {A  B.Example  R = (A. B  C. AB  C} NO  Is C extraneous in A  BC  {A  BC. AB  C} ? {A  B. C) F = {A  BC. B. B  C. AB  C}  Is B extraneous in A  BC  {A  BC. B  C.AB  C}  Combine A  BC and A  B into A  BC  Set is now {A  BC. B  C. B  C.