问题
I have a relation A,B,C,D,E with functional dependencies
1) A->BC
2) CD->E
3) B->D
4) E->A
Using 1 gives A,D,E and then using 4 will make it D,E
Using 2 gives A,B,C,D and then using 3 gives A,B,C and using 1 gives A
Using 2 gives A,B,C,D and using 1 gives A,D
Using 4 gives B,C,D,E and using 2 gives B,C,D and using 3 gives B,C
Using 3 gives A,B,C,E and using 1 gives A,E and using 4 gives E
So I would have 5 super keys? (A, E, AD, BC, DE). And from my super keys I would pick the unique ones.
Since I can get A from E, I can remove A and AD(since DE is the same) and since I can get BC from A I can remove that so I am left with
E, DE
Would that be my super key? Or would it just be E?
回答1:
By definition, a candidate key K of a relation is a set of attributes that determines all the others and such that we cannot remove any attribute from it without losing this property.
To find all the keys of the relation, if you do not follow a formal algorithm, then you could start by checking from each determinant of the FDs and see if this is a (super or candidate) key, by calculating its closure. For instance, starting from A, you can find:
A+ = A
= ABC (by using 1)
= ABCD (by using 3)
= ABCDE (by using 2)
So, A determines all the attributes and for this reason is a candidate key (and not a strict superkey, since you cannot remove any attribute from it!)
Calculating the closures of the other determinants, you can find that:
CD+ = ABCDE (candidate key, since C+ and D+ do not contain all the attributes)
B+ = BD (not a key)
E+ = ABCDE (candidate key)
Now you have three candidate keys, A, E, and CD. And since B determines only D, we could try to add something to it to see if it can be part of a key. We do not add A, or E, since they are already keys, and we do not add D since it is already determinated by B (so that having it will produce surely a superkey). So we try C:
BC+ = ABCDE (candidate key, since B+ and C+ do not contain all the attributes)
So, finally, we can say that the relation has four (and only four) candidate keys:
A
BC
CD
E
来源:https://stackoverflow.com/questions/43465696/how-to-find-a-candidate-key