Search code examples
sqlcandidate-key

What does the "minimality" mean in database candidate keys?


I was very confused by the idea given by my professor when studying about candidate key (but i feel sham to ask him :p )

"no component of K can be eliminated without destroying the uniqueness property --- minimality"

And i searched on wiki it says

"there is no proper subset of these attributes for which (1) holds (which means that the set is minimal)." It also give an example but i don't understand.

So my question is what does the "eliminated" here means? if it means remove the whole rows of data, then it should always keep the uniqueness of the data(because you can't lose uniqueness by removing a row of data). If it means only remove the single attribute of K and left a row with a empty "block", it looks silly and will destroy the data. So can someone give me some simple example for what does this property mean?(maybe one for the good one and one for the bad one) Thank you~


Solution

  • "Elimination" here does not touch the data at all. It just means that you remove one attribute/column from your key. If that reduced set of columns is still a key (i.e. uniquely identifies any data row), then the previous key was not minimal.

    Example:

    name id amount
    A    1  1000
    B    2  2000
    C    3  1000
    

    You could use name or id as a minimal key.

    You could also use [name, id] as a (compound, multi-column) key. But that key is not minimal (because you can remove one column from it and still have a key).

    The column amount in itself does not make a key at all.

    [amount, id] would be a key, but again, it is not minimal.