COUNTING SUPERKEYS
One candidate key K, ∣R∣=n:Keys K1,K2:2n−∣K∣2n−∣K1∣+2n−∣K2∣−2n−∣K1∪K2∣
A superkey is any set containing at least one candidate key. For more keys, extend by inclusion and exclusion over unions of keys. Example: keys AB, BC, BD in R(A,B,C,D) give 3⋅4−3⋅2+1=7.
MAXIMUM NUMBER OF CANDIDATE KEYS
at most (⌊n/2⌋n) candidate keys for n attributes
No candidate key contains another, and this bound is reached (for example, when every set of ⌊n/2⌋ attributes is a key).
A minimal cover is not unique, and two minimal covers of the same F can even have different numbers of FDs. For example, F={A→B,B→A,B→C,C→B,A→C,C→A} has the minimal covers {A→B,B→C,C→A} (three FDs) and {A→B,B→A,A→C,C→A} (four FDs). Always do step 2 before step 3: removing an extraneous attribute can make another FD redundant, which step 3 would then miss.
WORKED EXAMPLE
R(A,B,C,D,E) has F = {AB → C, C → D, D → E, E → C}. Find all candidate keys, the prime attributes and the highest normal form.
▸ Solution
A and B never appear on a right side, so both are in every key. (AB)+=AB→ABC→ABCD→ABCDE=R.
So AB is a key. It is the only one, because every key must contain AB, and any proper superset of AB is not minimal.
Prime attributes: A, B. Non-prime: C, D, E.
2NF test: A+=A and B+=B, so no proper subset of AB determines a non-prime attribute. The relation is in 2NF.
3NF test: C→D has C not a superkey and D non-prime. So the relation is not in 3NF.
Answer: Only key AB; prime = {A, B}; the relation is in 2NF but not 3NF.