简体   繁体   English

SQL Server中的Unicode唯一约束

[英]Unicode in SQL Server unique constraints

Consider the following script - the second INSERT statement throws a primary key violation. 考虑以下脚本-第二条INSERT语句引发主键冲突。

BEGIN TRAN

CREATE TABLE UnicodeQuestion
(
    UnicodeCol NVARCHAR(100)
    COLLATE Latin1_General_CI_AI
)

CREATE UNIQUE INDEX UX_UnicodeCol
ON UnicodeQuestion ( UnicodeCol )

INSERT INTO UnicodeQuestion (UnicodeCol) VALUES (N'ae')
INSERT INTO UnicodeQuestion (UnicodeCol) VALUES (N'æ')

ROLLBACK

As I understand it, if I want to have my index treat these values separately, I need to use a binary collation. 据我了解,如果我想让索引单独处理这些值,则需要使用二进制排序规则。 But there are many binary collations, and they have individual cultures in their names! 但是,有许多二进制排序规则,它们的名称中有各自的文化! I don't want culture-sensitive treatment... 我不要对文化敏感的治疗...

Which collation should I use when storing arbitrary Unicode data in nvarchar columns? 在nvarchar列中存储任意Unicode数据时,应该使用哪种排序规则?

For Unicode data it is irrelevant what binary collation you choose . 对于Unicode数据,选择哪种二进制排序无关紧要

For Unicode data types, data comparisons are based on the Unicode code points. 对于Unicode数据类型,数据比较基于Unicode代码点。 For binary collations on Unicode data types, the locale is not considered in data sorts. 对于Unicode数据类型的二进制排序规则,在数据排序中不考虑语言环境。 For example, Latin_1_General_BIN and Japanese_BIN yield identical sorting results when used on Unicode data. 例如,当在Unicode数据上使用Latin_1_General_BIN和Japanese_BIN时,将产生相同的排序结果。

The reason for having locale specific BIN collations is that this determines the code page used when dealing with non Unicode data. 具有特定于语言环境的BIN归类的原因是,这确定了处理非Unicode数据时使用的代码页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM