[英]SQL Server unique constraint issue on unicode characters
我的表定義如下:
create table [Language](
Id int primary key identity,
Code varchar(11) not null unique,
NativeName nvarchar(50) not null unique
)
然后,我有一長串插入該表的語句。 問題是一些插入語句與我的NativeName
列的唯一約束沖突。 奇怪的是,內容並不是唯一的。 例如,如果我只插入以下表空:
insert into Language (Code, NativeName) values('am', N'አማርኛ');
insert into Language (Code, NativeName) values('dv', N'ދިވެހިބަސް');
我得到第二次插入。
Violation of UNIQUE KEY constraint 'UQ__Language__EB1957A5F98D1F9C'. Cannot insert duplicate key in object 'dbo.Language'. The duplicate key value is (ދިވެހިބަސް).
有誰知道為什么unicode字符會導致這些問題?
嘗試使用更具體(二進制)的排序規則聲明NativeName列。
例如:
NativeName nvarchar(50) collate SQL_Latin1_General_CP437_BIN not null unique
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.