Subset of a candidate key

廉价感情. 提交于 2019-12-11 22:40:58

问题


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.



来源:https://stackoverflow.com/questions/24980587/subset-of-a-candidate-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!