数据库的五个Key:

  • Candidate Keys 候选键 : one or n attributes that can uniquely identify a record. 具有唯一性,最小性.
  • Primary Keys 主键 : 从候选键中,挑选出其中一个键,也就是最具识别意义(用于排序)的一个键. 具有唯一性.
  • Alternate(Secondary ) Keys 次要键 : Candidate Key 中除了Primary Key之外,剩余的key。
  • Super keys 超键 : any candidate key 并 any attributes in the table.
  • Foreign Keys 外(部)键 : 被用来参考到其他表格主键的关联键.
For example:学生资料表
(student_id, student_no, student_name, student_depid)
其中: 
student_id表示学生身分证字号
student_no表示学生学号
student_name表示学生姓名
student_depid表示学生的科系代号

则:
Candidate Key : 就可以是 {student_id}或者{student_no}.

Primary Key :  从Candidate Key挑选一个,至于挑选哪一个,就看你的系统特性.

Alternate(Secondary ) Key : 就是没被挑中当成Primary Key的其他Candidate Key,例如,如果挑选 {student_id}当成主键,Alternate(Secondary ) Key 就是{student_no}

Super key:  就可以是 {student_id}、{student_no}、 {student_id, student_no}、{student_id, student_name}、{student_id, student_depid} ... 等等,都符合唯一性的条件。

若存在科系资料表depentment (depid, dep_name),而且depid当成科系资料表的主键,学生资料表的 student_depid就是Foreign Key。
Logo

更多推荐