How to obtain a minimal key from functional dependencies?

白昼怎懂夜的黑 提交于 2020-01-01 10:57:11

问题


I need some help and guidelines.

I have the following relation: R = {A, B, C, D, E, F} and the set of functional dependencies

F = {
  {AB -> C};
  {A  -> D};
  {D  -> AE};
  {E  -> F};
}

What is the primary key for R ?

If i apply inference rules i get these additional Function dependencies:

D -> A
D -> E
D -> F

D -> AEF

A -> E
A -> F
A -> DEF

How do I continue?


回答1:


There is a well known algorithm to do this. I don't remember it, but the excercise seems to be simple enough not to use it.

I think this is all about transitivity:

CurrentKey = {A, B, C, D, E, F}

You know D determines E and E determines F. Hence, D determines F by transitivity. As F doesn't determine anything, we can remove it and as E can be obtained from D we can remove it as well:

CurrentKey = {A, B, C, D}

As AB determines C and C doesn't determine anything we know it can't be part of the key, so we remove it:

CurrentKey = {A, B, D}

Finally we know A determines D so we can remove the latter from the key:

CurrentKey = {A, B}

If once you have this possible key, you can recreate all functional dependencies it is a possible key.

PS: If you happen to have the algorithm handy, please post it as I'd be glad to re-learn that :)




回答2:


Algorithm: Key computation (call with x = ∅)

procedure key(x;A;F)
foreach  ! B 2 F do
if   x and B 2 x and B ̸2  then
return; /* x not minimal */
fi
od
if x+ = A then
print x; /* found a minimal key x */
else
X   any element of A 􀀀 x+;
key(x [ fXg;A;F);
foreach  ! X 2 F do
key(x [ ;A;F);
od
fi


来源:https://stackoverflow.com/questions/10164289/how-to-obtain-a-minimal-key-from-functional-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!