Subset of a candidate key

2019-08-31 04:21发布

问题:

As we know a candidate key is a column or combination of columns that uniquely identifies the rows in a relation.

Suppose I have a relation in which candidate keys are combinations of columns. I want to ask,

is it possible that a subset of a candidate key also uniquely identifies the row?

OR

is a candidate key a key for which there is no subset that uniquely identifies the row?

回答1:

A candidate key is a column or combination of columns. Or more correctly a set of one or more columns. Or more correctly a set of columns.

A candidate key is a set of columns that uniquely identifies rows and that contains no smaller ("proper") subset of columns that uniquely identifies rows.

A superkey is a set of columns that uniquely identifies rows. So a candidate key is a superkey that contains no smaller superkey.

In SQL you can't declare an empty candidate key. Also, UNIQUE NOT NULL and PRIMARY KEY (which in terms of constraints just means UNIQUE NOT NULL) declare superkeys, not keys per se. If such a declaration's column set doesn't contain a smaller column set declared as a superkey then the superkey it's declaring is a candidate key.

Your question originally said that you had a relation in which candidate keys are a "combination of keys". Maybe you meant something like, some smaller subset of (columns of) a superkey is a superkey or candidate key.

So no, a candidate key cannot contain a smaller candidate key. On the other hand in SQL you can have a UNIQUE/PK declaration on a smaller subset of the columns of another UNIQUE/PK declaration. But then the latter won't be a candidate key.



回答2:

By definition, no proper subset of a candidate key can identify a row.