候选键 主键 超键

来源:互联网 发布:代练软件 编辑:程序博客网 时间:2024/06/04 18:00

Candidate key 候选键
A Candidate key is a set of one or more attributes that can uniquely identify a row in a given table.

Primary Key 主键
During the creation of the table, the Database Designer chooses one of the Candidate Key from amongst the several available, to uniquely identify row in the given table.
The candidate key that is chosen to perform the identification task is called the primary key.

Alternate Key
The candidate key that is chosen to perform the identification task is called the primary key and the remaining candidate keys are known as alternate keys.

Super Key 超键
Any superset of a candidate Key is a super key.
超键能唯一标识记录。
候选键是没有多余属性的超键。

Foreign Key 外键
A Foreign Key is a set of attributes whose values are required to match values of a Candidate key in the same or another table.
The attributes other than the Primary Key attributes in a table/relation are called Non-Key attributes.

员工信息表:员工号,姓名,身份证号,性别,年龄

员工号唯一,是一个超键。
身份证号唯一,是一个超键。
(员工号,姓名)唯一,是一个超键。
(员工号,姓名,身份证号)唯一,是一个超键。

员工号唯一,没有多余属性,是一个候选键。
身份证号唯一,没有多余属性,是一个候选键。

考虑查询的便利,可以选择员工号为主键,也可以选择身份证号为主键。