主键和唯一键之间的差异 [英] difference between primary key and unique key
本文介绍了主键和唯一键之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用mysql数据库。我有主键和唯一键之间的混乱。
请帮助我在哪里创建主键和唯一键。
主键:
$ b < NULL
- eg MySQL添加 NOT NULL
唯一键:
- 可以是多个唯一键
- 可以是候选键
- 唯一键可以有空值 可以为空,并且可能不是唯一的
I'm using mysql database. I have a confusion between primary key and unique key.
Please help me where should I create primary and unique key. I mean in which situation we create unique key or primary key .
解决方案
Primary Key:
- Can be only one in a table
- In some DBMS it cannot be
NULL
- e.g. MySQL addsNOT NULL
- Primary Key is a unique key identifier of the record
Unique Key:
- Can be more than one unique key in one table
- Unique key can have null values
- It can be a candidate key
- Unique key can be null and may not be unique
这篇关于主键和唯一键之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文