SQL Server 2005如何创建唯一约束? [英] SQL Server 2005 How Create a Unique Constraint?
本文介绍了SQL Server 2005如何创建唯一约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在SQL Server 2005中的现有表上创建唯一约束?
How do I create a unique constraint on an existing table in SQL Server 2005?
我正在寻找TSQL以及如何在数据库图。
I am looking for both the TSQL and how to do it in the Database Diagram.
推荐答案
SQL命令是:
ALTER TABLE <tablename> ADD CONSTRAINT
<constraintname> UNIQUE NONCLUSTERED
(
<columnname>
)
完整语法此处。
如果你想从数据库图:
- 右键单击表并选择Indexes /键
- 点击添加按钮添加新索引
- 在右侧的属性中输入必要的信息:
- 您想要的列(点击省略号按钮进行选择)
- 将唯一设置为Yes
- 给它一个适当的名称
- right-click on the table and select 'Indexes/Keys'
- click the Add button to add a new index
- enter the necessary info in the Properties on the right hand side:
- the columns you want (click the ellipsis button to select)
- set Is Unique to Yes
- give it an appropriate name
这篇关于SQL Server 2005如何创建唯一约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文