SQL_Latin1_General_CP1_CI_AS与SQL_Latin1_General_CP1_CI_AI之间的区别是什么

时间:2013-03-19 23:16:31

标签: tsql

我在Microsoft SQL Server中运行更新查询时出现此错误

  

无法在等于操作的情况下解决“SQL_Latin1_General_CP1_CI_AS”和“SQL_Latin1_General_CP1_CI_AI”之间的排序规则冲突。

查询只使用2个表,它正在更新的表和一个内部连接的临时表,我没有指定表的排序规则,它们都在同一个数据库中,这意味着它们应该具有相同的排序规则因为它应该是数据库默认的一个

查看排序规则,唯一的区别是最后一个字符,我所理解的最后一部分是CI代表Case Insensitive。如果我在黑暗中采取刺,我会认为AI代表自动增量,但我不知道AS代表什么

1 个答案:

答案 0 :(得分:17)

AI代表口音不敏感(即确定咖啡馆=咖啡馆)。 您可以使用collat​​e关键字转换一个(或两个)值的排序规则 有关详细信息,请参阅链接: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
café cafe
store store store
fiancé fiance
ampère ampere
cafétería cafétería cafétería
fête fete
jalapeño jalapeno
über uber
zloty zloty zloty
Zürich Zurich