我的 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模板网!
我应该使用什么 SQL Server 数据类型来存储字节 What SQL Server Datatype Should I Use To Store A Byte[](我应该使用什么 SQL Server 数据类型来存储字节 [])
解释 SQL Server 中 sys.objects 中的类型代码Interpreting type codes in sys.objects in SQL Server(解释 SQL Server 中 sys.objects 中的类型代码)
Typeorm .loadRelationCountAndMap 返回零Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
MS SQL:ISDATE() 是否应该返回“1"?什么时候不能MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否应该返回“1?什么时候不能投射为日期?)
将一天的名称转换为其整数表示Converting the name of a day to its integer representation(将一天的名称转换为其整数表示)
如何在 SQL Server 中将 nvarchar m/d/yy 转换为 mm/dd/yHow to convert nvarchar m/d/yy to mm/dd/yyyy in SQL Server?(如何在 SQL Server 中将 nvarchar m/d/yy 转换为 mm/dd/yyyy?)