数据库中五个Key(鍵)的概念区分

数据库的五个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。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Laura_Wangzx

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值