10

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

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

该查询仅使用 2 个表,它正在更新的表和一个它执行内部联接的临时表,我没有指定这两个表的排序规则,它们都在同一个数据库上,这意味着它们应该具有相同的排序规则,因为它应该成为数据库默认的一项权利

查看排序规则,唯一的区别是最后一个字符,我对最后一部分的理解是 CI 代表不区分大小写。如果我要在黑暗中冒险,我会认为 AI 代表 Auto Increment,但我不知道 AS 代表什么

4

1 回答 1

21

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íacaféteríacafétería
fête fete
jalapeño jalapeno
über uber
zloty zloty zloty
Zürich Zurich

于 2013-03-19T23:26:43.280 回答