开发者

Why Microsoft has put 2 different options for creating Unique Indexes on a table in SQL Server 2005?

开发者 https://www.devze.com 2022-12-30 02:02 出处:网络
Why Microsoft has put 2 different options for creating Unique Indexes on a table in SQL Server 20开发者_如何学运维08?

Why Microsoft has put 2 different options for creating Unique Indexes on a table in SQL Server 20开发者_如何学运维08?

Manage Indexes/Keys :

1 ) type = Unique Key ==> IsUnique = Yes (IsUnique is disabled) 2 ) type = Index ==> IsUnique = Yes

Thank you


They map to two different SQL commands:

ALTER TABLE … ADD CONSTRAINT … UNIQUE

and

CREATE UNIQUE INDEX … ON …

CONSTRAINT UNIQUE is a logical concept, while UNIQUE INDEX is its physical implementation.

In SQL Server, CONSTRAINT UNIQUE is always backed up by a unique index which is implicitly created with the same name as the constraint, so these commands are effectively the same.

The only difference from user's point of view is that the constraint can be implicitly named, but you should always provide an explicit name for an index.


This is what Google finds (for SQL Server 2000 though):

The short answer is that a unique index is just an index, whereas a unique constraint is a unique index that's listed as a constraint object in the database. In the sysobjects table, the unique constraint will have an xtype value of "UQ." But does a unique constraint have any additional behavior that a unique index doesn't have—or vice versa? The answer to that question, it turns out, takes a big of digging.

...

Source: Unique Constraints and Unique Indexes

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号