How to find a candidate key

前端 未结 1 1189
闹比i
闹比i 2021-01-22 19:21

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

1条回答
  •  失恋的感觉
    2021-01-22 19:53

    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
    

    0 讨论(0)
提交回复
热议问题