-1

Example:

Let R = (A, B, C, D) Let F = {C -> AD, AB -> C}

Then how can I find the candidate keys?

The answer is {AB, BC}

Why?

philipxy
  • 14,867
  • 6
  • 39
  • 83
Na Jun Yeop
  • 55
  • 1
  • 7
  • What reference are you using? Where are you stuck applying it? Please google 'stackexchange homework'. You are just asking for a chapter/sections of a textbook with a specialized example. That is too broad. – philipxy Oct 13 '17 at 19:19

1 Answers1

0

Given a relation schema R with a set of attributes T and a non-empty set of non-trivial functional dependencies F describing a certain set of constraints that are assumed to hold in that schema:

  1. Every attribute that does not appear in the right part of a FD in F must be present in any candidate key.

  2. Every attribute that does not appear in the left part of a FD in F cannot be present in any candidate key.

To find all the candidate keys, for all the other attributes, you should try to add to the attributes of 1 above every possible combination of them, and see if the closure determines all the attributes of the relation (and such that you cannot remove any attribute from the combination without losing this property).

Note that, if the set F is empty, the only candidate key is constituted by all the attributes T.

In practice there are algorithms that can be relatively efficient (since the problem of finding all the keys is in the general case exponential).

A simple approach is to start from a canonical cover of the functional dependencies, in this case for instance from:

{ A B → C
  C → A
  C → D }

and after finding the attributes that must be present in any candidate key (in this case B), try to add to them the left hand side of the dependencies (in this case both AB, that is A, and C) (in any order, and possibly combining them) and compute the closure to see if they determine all the attributes. When you discover that some set of attributes determines all the relation attributes, you have found a candidate key (and it is not necessary to add other attributes to it). In your example:

 (A B)+ = A B C D
 (B C)+ = A B C D

So A B and B C are candidate keys (since you cannot remove any attribute to both of them without losing the property of determining all the other attributes). And since there are no other attributes (a part from D that cannot be present in a candidate key), you know that you have found all the candidate keys.

Renzo
  • 26,848
  • 5
  • 49
  • 61
  • Every attribute determines itself, so your 1 & 2 are vacuous, unless you are assuming something about the FDs, like they are non-trivial. But the only CK may itself be trivial (all the attributes), so 2 is wrong & you can't discount attributes of trivial FDs for finding CKs.The part before "in practice" is not clear about finding CKs. I'd suggest a repair but it's not immediately clear to me how to modify this presentation to keep its style/approach/essence (what ever that might be) but make it accurate. – philipxy Oct 13 '17 at 19:42
  • @philipxy, I tried to correct the answer. If you think it is still too buggy and/or confused, I will delete it. – Renzo Oct 13 '17 at 23:15
  • The bullets are used in your algorithm. They really belong within it as sub-steps. Ie the algorithm's minimal cover is really the context your bullets make sense in. But you are missing a final step of adding non-cover attributes to those generated by the FD part. So I basically suggest you present the actual algorithm as published somewhere... *like the asker's textbook, that they are ignoring*. Maybe not as tersely, but maybe more concisely than in your answer now. Or just find an SO duplicate. "How can I find candidate keys?" Give me a break. – philipxy Oct 14 '17 at 00:12
  • You seem to be introducing & motivating the algorithm in the second part by first giving the bullets, which it uses, & a brute-force algorithm starting from 1 & limited by 2. I don't think you can make the bullets work outside an algorithm that assumes F is canonical and that adds unmentioned attributes later. 2 is still false for attributes not in F. F+ is still needed. A clear definition is lacking--a smallest set that determines all attributes--1 & 2 just *complicate* the brute force search. Anyway the two paragraphs after the bullets are not clear. PS Hm... *is* there a decent SO answer? – philipxy Oct 14 '17 at 03:03
  • I notice that my comments are quite terse but the fact is that your presentation of an algorithm is not clear, although I am sure that you can make it clear. – philipxy Apr 07 '19 at 19:51