我的 SQL Server 数据库中有一个简单的表.该表包含两列:ID int, Name nvarchar(50)
.ID
列是我的表的主键.
I have a simple table in my SQL Server database. This table contains two columns: ID int, Name nvarchar(50)
. The ID
column is the primary key for my table.
我希望Name
"列是(No Duplicates)
",就像在 Microsoft Access 中一样,但此列不是主列.我怎么能这样做?
I want the "Name
" column to be "(No Duplicates)
", like in Microsoft Access, But this column isn't the primary column. How could I do this?
添加 该列的唯一约束:
ALTER TABLE Foo ADD CONSTRAINT UQ_Name UNIQUE (Name)
<小时>
通过 SQL Management Studio UI 添加:
To add it through SQL Management Studio UI:
要处理发生唯一约束违反的情况,请参阅错误2601.
To handle a situation where a unique constraint violation occurs, see for error 2601.
这篇关于如何制作“无重复"SQL Server 2008 中的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!