2

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?

4

1 回答 1

3

根据定义,关系的候选键 K 是一组属性,这些属性决定了所有其他属性,因此我们不能从中删除任何属性而不会丢失该属性。

要找到关系的所有键,如果您不遵循正式算法,那么您可以从检查 FD 的每个行列式开始,并通过计算其闭包来查看这是否是(超级或候选)键。例如,从 A 开始,您可以找到:

A+ = A
   = ABC (by using 1)
   = ABCD (by using 3)
   = ABCDE (by using 2)

因此,A 确定所有属性,因此是候选键(而不是严格的超级键,因为您不能从中删除任何属性!)

计算其他行列式的闭包,您可以发现:

CD+ = ABCDE (candidate key, since C+ and D+ do not contain all the attributes)
B+ = BD (not a key)
E+ = ABCDE (candidate key)

现在您有了三个候选键,A、E 和 CD。由于 B 只确定 D,我们可以尝试向它添加一些东西,看看它是否可以成为键的一部分。我们添加 A 或 E,因为它们已经是键,并且我们添加 D,因为它已经由 B 确定(因此拥有它肯定会产生一个超级键)。所以我们尝试C:

BC+ = ABCDE (candidate key, since B+ and C+  do not contain all the attributes)

所以,最后,我们可以说这个关系有四个(也只有四个)候选键:

A
BC
CD
E
于 2017-04-18T09:06:05.547 回答