Can a relation have Candidate Keys with different lengths?

▼魔方 西西 提交于 2020-07-11 05:58:36

问题


We can have more than one candidate key in a relation. But can we have two candidate keys in a relation different in length?

Suppose I have a relation R(A,B,C,D,E) and we have only two sets of attributes which uniquely identify a tuple in the relation: {A,B,C} and {D,E}.

So can we say both {A,B,C} and {D,E} are candidate keys?


回答1:


But can we have two candidate keys in a relation different in length?

Yes.

A CK (candidate key) is a superkey (unique column set) that doesn't contain a smaller one.

So we sometimes say a CK is a "minimal" superkey, using "minimal" in this sense of a particular superkey not being able to be made into smaller superkey by removing attributes. It doesn't mean some other thing that might come to mind. In particular it doesn'tmean a CK that has fewer attributes than any other CK or no more attribtutes than another CK.

You need to learn the definitions of technical terms. Names don't tell you anything.

There's also no point in worrying about things you notice while following a definition. Just follow it.

Suppose I have a relation R(A,B,C,D,E) and we have only two sets of attributes which uniquely identify a tuple in the relation: {A,B,C} and {D,E}.

That is not possible. If {A,B,C} & {D,E} are unique, then all supersets of them are also unique. Eg the set of all attributes is always unique, here {A,B,C,D,E}.

Presumably what you mean is, we have only two minimal "sets of attributes which uniquely identify a tuple", ie only two CKs.

So can we say both ABC and DE are candidate keys?

You can if both those two unique sets don't contain smaller unique sets. By the definition of CK.




回答2:


In order for a combination of rows to be a primary key candidate if needs to fulfill two requirements:

a.) None of the columns may contain NULL values.

b.) The combination must be unique.



来源:https://stackoverflow.com/questions/45533608/can-a-relation-have-candidate-keys-with-different-lengths

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