Key和Index与IsUnique

Key和Index与IsUnique

本文介绍了Unique Key和Index与IsUnique = Yes之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主键的表,但我想要限制其他两列,以保证两者的组合始终是唯一的。

I have a table with a primary key, but I want two other columns to be constrained so the combination of the two is guaranteed always to be unique.

一个哑的例子:在BOOKS表中,IBAN列是主键,但是Title和Author列的组合也应该是唯一的。)

(a dumb example: In a BOOKS table, the IBAN column is the primary key, but the combination of the Title and Author columns should also always be unique.)

SQL Server Management Studio可以创建一个新的索引并将IsUnique设置为Yes,或者我可以创建一个新的唯一键。

In the SQL Server Management Studio it's possible to either create a new Index and set IsUnique to Yes, or I can create a new Unique Key.

两种方法之间的区别是什么

What is the difference between the two approaches, and which one suits best for which purposes?

推荐答案

创建一个UNIQUE约束是一个更清晰的规则语句。索引的IsUnique属性是实施细节 - 如何实施规则,而不是规则是什么。效果是一样的。

Creating a UNIQUE constraint is a clearer statement of the rule. The IsUnique attribute of the index is an implementation detail - how the rule is implemented, not what the rule is. The effect is the same though.

这篇关于Unique Key和Index与IsUnique = Yes之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 13:32