候选键的要点是什么? [英] What's the point of a candidate key?
问题描述
我对数据库管理相当陌生,这个问题似乎没有在一个句子中回答。所有其他的SO答案说候选键是最小的超级键。这对我来说没有任何意义。
I'm fairly new to database management and this question never seems to be answered in more than one sentence. All other SO answers say "A candidate key is a minimal super key." That means nothing to me.
候选键应该指定db记录的唯一性,正确吗?主键是候选键。如果主键已经指定了唯一性,添加更多候选键的要点是什么?
A candidate key is supposed to specify uniqueness of a db record, correct? And a primary key is a candidate key. If a primary key already specifies uniqueness, what's point of adding more candidate keys?
我已经看到像以下示例记录:
I have seen example records like the following:
员工(ID,姓名,电话号码)
Employee(ID, Name, PhoneNumber)
其中ID是主键,PhoneNumber是候选键。从我看到的,ID足以指定员工记录的唯一性。
where ID is the primary key and PhoneNumber is a candidate key. From what I see, the ID is enough to specify the uniqueness of an employee record. Although PhoneNumbers are (probably) unique, specifying them as a candidate key does not seem "minimal" to me.
推荐答案
这意味着我们可以使用电话号码如果PhoneNumber确实是候选键,您可以删除ID列,并使用PhoneNumber。
It means that if PhoneNumber was indeed a candidate key you could delete the ID column and use PhoneNumber instead. In other words, it is a candidate for being a unique key.
维基百科拥有更多正式定义,你很想看看。
Wikipedia has a more formal definition that you many want to look at.
这篇关于候选键的要点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!