# Find number of candidate keys given non-trivial functional dependency X->Y, where X is some set of attributes and Y is some prime attribute

In a relation R, if X is some set of attributes and Y is some prime attribute such that X uniquely determines Y is a non-trivial FD. Then is it true that R has at least two candidate keys?

For instance, take the relation schema R(Class_Id, Course_Number, Instructor_Name, Text). {Class_Id, Course_number} is a candidate key. This makes Course_Number a prime attribute.

The following functional dependency holds on R:

• {Instructor_Name, Text} uniquely determines {Course_Number}

How to determine if another candidate key exist or not?

EDIT: A Relational table

Class_Id | Course_Number | Instructor_Name | Text

2             b            Jodi           E
3             c            Jack           N
2             c            Jack           N
4             b            Peny           E
5             e            Jodi           N


X -> Y non-trivial means that X does not include Y. Since Y is a prime attribute, we know that there is at least a candidate key that include it. Let's call this key K1.

Now we have two cases: either X is a superkey, or not.

If X is a superkey, then it contains at least a candidate key K. We can easily convince that K ≠ K1, since it differ from K1 by at least one attribute.

So in this case in the relation there are at least two different candidate keys, K and K1.

Now suppose that X is not a superkey, and consider X ∪ (K1 - {Y}). This is surely a superkey, since it determines K1, which determines all the attributes. This superkey does not contains Y, but contains at least a candidate key K', so again we have at least two different candidate keys, K' and K1.

Edit

Let's see in a more formal way why X ∪ (K1 - {Y}) is a superkey.

A superkey is a set of attributes that determines all the attributes of the relation, and we can check this property by computing its closure and see if it contains all the attributes of the relation (let's call them T).

Since K1 is a candidate key, we know that:

(1) K1 -> T


we also know:

(2) X -> Y
(3) Y ∈ K1


So we can calculate the closure of X ∪ (K1 - {Y}) in this way:

(4) (X ∪ (K1 - {Y}))+ = X ∪ (K1 - {Y})
(5) (X ∪ (K1 - {Y}))+ = X ∪ (K1 - {Y}) ∪ Y = X ∪ K1  by (4) and (2)
(6) (X ∪ (K1 - {Y}))+ = X ∪ K1 ∪ T = T by (5) and (1)


so we can conclude that (X ∪ (K1 - {Y}))+ contains T, and, consequently, that (X ∪ (K1 - {Y})) is a superkey.

• I am not convinced by the argument in the case of when X is not a superkey, where you have said "This is surely a superkey, since it determines K1, which determines all the attributes.". Please tell me how did you come to the conclusion that X U (K1 - {Y}) is a superkey. Though I verified it with an instance of relation table (please see edit), your argument holds there. – Haslo Vardos Jan 14 at 17:34
• I changed the answer. – Renzo Jan 14 at 19:03