Consider R(A,B,C,D,E)
F = {BC->AE, A->D, D->C, ABD->E}
.
I need to find all candidate key of the schema.
I know that BA
,BC
,BD
are the keys, but i want to know how do discover them.
I saw some answers in candidate keys from functional dependencies = but i didn't fully understand them.
form what they suggest, I got L={B}
, M={A,C,D}
, R={E}
Now i need to add from M
one at a time to L
.
I start with A
, i get BA
. So BA->A
, BA->B
(trivial) and because A->D
so BA->D
and because D->C
we get BA->C
.
But, how we get E
?
adapting the answer from https://stackoverflow.com/a/14595217/3591273
Since we have the functional dependencies: BC->AE, A->D, D->C, ABD->E
, we have the following superkeys:
ABCDE
(All attributes is always a super key)ABCD
(We can get attribute E
through ABD -> E
)ABC
(Just add D
through A -> D
)ABD
(Just add C
through D -> C
)AB
(We can get D
through A -> D
, and then we can get C
through D -> C
)BC
(We can get E
through BC -> E
, and then we can get C
through D -> C
)BD
(We can get C
through D -> C
, and then we can get AE
through BC -> AE
)(One trick here to realize, is that since B
never appears on the right side of a functional dependency, every key must include B
, ie key B
is independent and cannot be derived from other keys)
Now that we have all our super keys, we can see that only the last three are candidate keys. Since the first four can all be trimmed down. But we cannot take any attributes away from the last three superkeys and still have them remain a superkey.
so the minimal keys are AB
, BC
, BD
update
this was a reduction approach, i.e succesively reduce the trivial superkey by use of functional dependencies, but one can take the opposite road and use an augment approach, i.e start with single trivial keys and augment them with other keys wrt dependency relations untill keys become superflous