我需要能够创建一个唯一约束来检查字符串和整数组合是否唯一。SQL Server - 如何跨多列创建唯一约束,其中一列是VARCHAR
我曾尝试代码:
ALTER TABLE mytable ADD CONSTRAINT
constraint_Unique_ForeignID_MyString UNIQUE NONCLUSTERED
(
foreign_id, my_string_col
)
,但我得到的错误:
Msg 1919, Level 16, State 1, Line 1
Column 'my_string_col' in table 'my_string_tbl' is of a type that is invalid for use as a key column in an index.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.
如何创建我需要的约束?
请给我们表定义吗? – gbn 2011-02-17 13:02:56