SQL_Latin1_General_CP1_CI_AS和SQL_Latin1_General_CP1_CI_AI有什么区别?

10
当我在Microsoft SQL Server中运行更新查询时,遇到以下错误:

无法解析“SQL_Latin1_General_CP1_CI_AS”和“SQL_Latin1_General_CP1_CI_AI”之间的排序冲突,因为它们在等于操作中。

查询只使用了两个表,被更新的表和一个临时表,后者进行内部连接。我没有指定这两个表的排序规则,它们都在同一个数据库中,应该有相同的排序规则,因为它应该是数据库默认的排序规则。
看着排序规则,唯一的区别是最后一个字符。我对最后一部分的理解只是CI代表不区分大小写。如果我猜测,“AI”代表自动增量,但我不知道“AS”代表什么。
1个回答

22

AI代表着不区分口音(即确定 cafe = café)。 您可以使用collate关键字来转换一个或两个值的排序规则。
有关更多信息,请参见链接:http://msdn.microsoft.com/en-us/library/aa258237(v=sql.80).aspx

示例:DBFiddle

--setup a couple of tables, populate them with the same words, only vary whether to accents are included
create table SomeWords (Word nvarchar(32) not null)
create table OtherWords (Word nvarchar(32) not null)

insert SomeWords (Word) values ('café'), ('store'), ('fiancé'), ('ampère'), ('cafétería'), ('fête'), ('jalapeño'), ('über'), ('zloty'), ('Zürich')
insert OtherWords (Word) values ('cafe'), ('store'), ('fiance'), ('ampere'), ('cafétería'), ('fete'), ('jalapeno'), ('uber'), ('zloty'), ('Zurich')

--now run a join between the two tables, showing what comes back when we use AS vs AI.
--NB: Since this could be run on a database of any collation I've used COLLATE on both sides of the equality operator
select sw.Word MainWord
, ow1.Word MatchAS
, ow2.Word MatchAI
from SomeWords sw
left outer join OtherWords ow1 on ow1.Word collate SQL_Latin1_General_CP1_CI_AS = sw.Word collate SQL_Latin1_General_CP1_CI_AS 
left outer join OtherWords ow2 on ow2.Word collate SQL_Latin1_General_CP1_CI_AI = sw.Word collate SQL_Latin1_General_CP1_CI_AI  

示例输出:

MainWord MatchAS MatchAI
咖啡馆 咖啡馆
商店 商店 商店
未婚夫 未婚夫
安培 安培
咖啡厅 咖啡厅 咖啡厅
庆祝 庆祝
辣椒 辣椒
优步 优步
兹罗ich 兹罗ich


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接