唯一约束和唯一索引 [英] unique constraint and unique index

查看:90
本文介绍了唯一约束和唯一索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


如何区分唯一约束和唯一索引?这些

非常相似,但我无法区分它们?


有人可以帮我一把吗?

提前谢谢

解决方案

" Laurence" < WO ********** @ hotmail.com>在消息中写道

news:11 ********************* @ 75g2000cwc.googlegrou ps.com ...

你好,

如何区分唯一约束和唯一索引?这些
非常相似,但我无法区分它们?

有人能帮我一把吗?
提前致谢




唯一约束将自动创建唯一索引,除非相同列上已存在

唯一索引。


唯一约束必须仅包含列定义为非null

(如PK)。一个唯一索引可以有一个可以为空的列(但空值是

不被忽略,它们在计算确定唯一性时计算)。


一个孩子的外键table可以引用父表

表的唯一约束(显然它也可以引用父表上的PK)。


< blockquote>Mark A <无**** @ nowhere.com>在消息中写道

新闻:es ****************************** @ comcast.com。 ..

唯一约束将自动创建唯一索引,除非同一列上已存在
唯一索引。

唯一约束必须只包含列被定义为非空
(如PK)。唯一索引可以有一个可为空的列(但是null值不会被忽略,它们会在确定唯一性时计算)。

子表上的外键可以引用一个唯一约束。
父表(显然它也可以在父表上引用PK)。




更正,第一句应该是:


唯一约束将自动创建唯一索引,除非相同列上已存在

唯一索引。



>一个唯一索引可以有一个可以为空的列(但是null值是

不被忽略,它们被计算在确定唯一性时)。


所以,它是否意味着同一列中的行只能有一个NULL

值?否则违反规则将被解雇?


Hi there,

How to differentiate between unique constraint and unique index? These
are very similar but I cannot differentiate them?

Could someone give me a hand?
Thanks in advance

解决方案

"Laurence" <wo**********@hotmail.com> wrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...

Hi there,

How to differentiate between unique constraint and unique index? These
are very similar but I cannot differentiate them?

Could someone give me a hand?
Thanks in advance



A unique constraint will automatically created a unique index, unless a
unique index already exists on the same columns.

A unique constraint must only contain columns that are defined as not null
(like a PK). A unique index can have a nullable column (but null values are
not ignored and they are counted in determining uniqueness).

A foreign key on a child table can reference a unique constraint on a parent
table (and obviously it can also reference a PK on a parent table).


"Mark A" <no****@nowhere.com> wrote in message
news:es******************************@comcast.com. ..

A unique constraint will automatically created a unique index, unless a
unique index already exists on the same columns.

A unique constraint must only contain columns that are defined as not null
(like a PK). A unique index can have a nullable column (but null values
are not ignored and they are counted in determining uniqueness).

A foreign key on a child table can reference a unique constraint on a
parent table (and obviously it can also reference a PK on a parent table).



Correction, first sentence should read:

A unique constraint will automatically create a unique index, unless a
unique index already exists on the same columns.



> A unique index can have a nullable column (but null values are
not ignored and they are counted in determining uniqueness).

So, does it mean the rows in the same column only can have one NULL
value? or otherwise the violation rule will be fired?


这篇关于唯一约束和唯一索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆