如何在我的列 (SQL Server 2008 R2) 上创建唯一约束? [英] How can I create a unique constraint on my column (SQL Server 2008 R2)?

查看:44
本文介绍了如何在我的列 (SQL Server 2008 R2) 上创建唯一约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 SQL Server 2008 R2,我想设置一个唯一的列.

I have SQL Server 2008 R2 and I want to set a unique column.

似乎有两种方法可以做到这一点:唯一索引"和唯一约束".它们与我所理解的没有太大区别,尽管大多数人都推荐使用唯一约束,因为您还可以自动获得索引.

There seems to be two ways to do this: "unique index" and "unique constraint". They are not much different from what I understand, although unique constraint is recommended by most, because you also get an index automatically.

如何创建唯一约束?

ALTER TABLE Customer ADD CONSTRAINT U_Name UNIQUE(Name)

有没有办法通过 SQL Server Management Studio 创建唯一约束?

Is there a way to create a unique constraint through the SQL Server Management Studio?

推荐答案

要通过 GUI 创建这些约束,您需要索引和键"对话框而不是检查约束.

To create these constraints through the GUI you need the "indexes and keys" dialogue not the check constraints one.

但在您的情况下,您只需要运行您已有的代码.完全不需要进入表情对话.

But in your case you just need to run the piece of code you already have. It doesn't need to be entered into the expression dialogue at all.

这篇关于如何在我的列 (SQL Server 2008 R2) 上创建唯一约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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