0% found this document useful (0 votes)
77 views17 pages

FD Keys

The document provides examples of functional dependencies and solutions to exercises involving functional dependencies. It discusses determining functional dependencies from relations and instances, finding candidate keys, and projecting functional dependencies onto subsets of attributes. The examples cover topics such as determining if a given functional dependency holds based on an instance, computing closures to check if a functional dependency follows logically, and identifying attributes that must or cannot be part of a candidate key.

Uploaded by

fragilewindows
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views17 pages

FD Keys

The document provides examples of functional dependencies and solutions to exercises involving functional dependencies. It discusses determining functional dependencies from relations and instances, finding candidate keys, and projecting functional dependencies onto subsets of attributes. The examples cover topics such as determining if a given functional dependency holds based on an instance, computing closures to check if a functional dependency follows logically, and identifying attributes that must or cannot be part of a candidate key.

Uploaded by

fragilewindows
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 17

Functional Dependencies-More Examples

January 9, 2013

Exercise #1

1. 2. 3.

Below is an instance of R(A1,A2,A3,A4). Choose the FD which may hold on R A4->A1 A2A3->A4 A2A3->A1

Solution #1
1. A4->A1 ??? Incorrect: The 1st and 4th tuple violates it 2. A2A3->A4 ??? Incorrect: The1st and 2nd tuple violates it. 3. A2A3 -> A1 ??? Correct!

Exercise #2
Let R(ABCDEFGH) satisfy the following functional dependencies: {A->B, CH->A, B->E, BD->C, EG->H, DE->F} Which of the following FD is also guaranteed to be satisfied by R? 1. BFG --> AE Hint: Compute the closure of the LHS 2. ACG --> DH of each FD that you get as a choice. If the RHS of the candidate FD is 3. CEG --> AB contained in the closure, then the

candidate follows from the given FDs, otherwise not.

Solution #2
FDs: {A->B, CH->A, B->E, BD->C, EG->H, DE->F} 1. BFG --> AE ???

Incorrect: BFG+ = BFGEH, which includes E, but not A


Incorrect: ACG+ = ACGBE, which includes neither D nor H. Correct: CEG+ = CEGHAB, which contains AB

2. ACG --> DH ???

3. CEG --> AB ???

Question #3
Which of the following could be a key for R(A,B,C,D,E,F,G) with functional dependencies {AB->C, CD->E, EF->G, FG>E, DE->C, and BC->A} 1. BDF 2. ACDF 3. ABDFG 4. BDFG

Solution #3 - 1
{AB->C, CD->E, EF->G, FG->E, DE->C, and BC>A} 1. BDF ??? No. BDF+ = BDF 2. ACDF ??? No. ACDF+ = ACDFEG (The closure does not include B) 3. ABDFG ??? No. This choice is a superkey, but it has proper subsets that are also keys (e.g. BDFG+ = BDFGECA)

Solution #3 - 2
{AB->C, CD->E, EF->G, FG->E, DE->C, and BC>A} 4. BDFG ??? BDFG+ = ABCDEFG Check if any subset of BDFG is a key:

Since B, D, F never appear on the RHS of the FDs, they must form part of the key. BDF+ = BDF Not key So, BDFG is the minimal key, hence the candidate key

Finding Keys using FDs


Tricks for finding the key: If an attribute never appears on the RHS of any FD, it must be part of the key If an attribute never appears on the LHS of any FD, but appears on the RHS of any FD, it must not be part of any key

Exercise #5
Consider R = {A, B, C, D, E, F, G, H} with a set of FDs F = {CDA, ECH, GHBAB, CD, EGA, HB, BECD, ECB} Find all the candidate keys of R

10

Solution #5 - 1
F = {CDA, ECH, GHBAB, CD, EGA, HB, BECD, ECB} First, we notice that:

EFG never appear on RHS of any FD. So, EFG must be part of ANY key of R A never appears on LHS of any FD, but appears on RHS of some FD. So, A is not part of ANY key of R We now see if EFG is itself a key EFG+ = EFGA R; So, EFG alone is not key
11

Solution #5 - 2

Checking by adding single attribute with EFG (except A): BEFG+ = ABCDEFGH = R; its a key [BECD, EGA, ECH] CEFG+ = ABCDEFGH = R; its a key [EGA, ECH, HB, BECD] DEFG+ = ADEFG R; its not a key [EGA] EFGH+ = ABCDEFGH = R; its a key [EGA, HB, BECD] If we add any further attribute(s), they will form the superkey. Therefore, we can stop here searching for candidate key(s). Therefore, candidate keys are: {BEFG, CEFG, EFGH}
12

Exercise #6
Consider R = {A, B, C, D, E, F, G} with a set of FDs F = {ABCDE, ABD, DEABCF, EC} Find all the candidate keys of R

13

Solution #6 - 1
F = {ABCDE, ABD, DEABCF, EC} First, we notice that:

G never appears on RHS of any FD. So, G must be part of ANY key of R. F never appears on LHS of any FD, but appears on RHS of some FD. So, F is not part of ANY key of R G+ = G R So, G alone is not a key!

14

Solution #6 - 2

Now we try to find keys by adding more attributes (except F) to G Add LHS of FDs that have only one attribute (E in EC): GE+ = GEC R Add LHS of FDs that have two attributes (AB in ABD and DE in DEABCF): GAB+ = GABD GDE+ = ABCDEFG = R; [DEABCF] Its a key! Add LHS of FDs that have three attributes (ABC in ABCDE), but not taking super set of GDE: GABC+ = ABCDEFG = R; [ABCDE, DEABCF] Its a key! GABE+ = ABCDEFG = R; [ABD, DEABCF] Its a key! If we add any further attribute(s), they will form the superkey. Therefore, we can stop here. The candidate key(s) are {GDE, GABC, GABE}
15

Exercise #7
Consider R = {A, B, C, D, E} with a set of FDs F = {ABDE, CE, DC, EA} And we wish to project those FDs onto relation S={A, B, C} Give the FDs that hold in S Hint: We need to compute the closure of all the subsets of {A, B, C}, except the empty set and ABC. Then, we ignore the FDs that are trivial and those that have D or E on the RHS
16

Solution #7
R = {A, B, C, D, E} F = {ABDE, CE, DC, EA} S={A, B, C} A+ = A B+ = B C+ = CEA [CE, EA] AB+ = ABDEC [ABDE, DC] AC+ = ACE [CE] BC+ = BCEAD [CE, EA, ABDE] We ignore D and E. So, the FDs that hold in S are: {CA, ABC, BCA} (Note: BCA can be ignored because it follows logically 17 from CA)

You might also like