具有完全相同架构的多个SQL Server数据库不知何故最终具有不同的排序规则。如何使用脚本方法将它们全部更改为相同而无需手动点击?
declare @rename_models table (
wrong nvarchar(256) COLLATE SQL_Latin1_General_CP1_CI_AS, -- tried overriding collation, but this conflicts with some of the databases
correct nvarchar(256) COLLATE SQL_Latin1_General_CP1_CI_AS
);
我针对models
表运行的查询:
select code as to_be_deleted from models where code in (select wrong from @rename_models);
对某些数据库抛出此内容:
MESSAGE
"Msg 468, Level 16, State 9, Line 140
Cannot resolve the collation conflict between ""SQL_Latin1_General_CP1_CI_AS"" and ""Latin1_General_CI_AS"" in the equal to operation.
答案 0 :(得分:1)
您可以在选择查询中使用COLLATE关键字
转换表达式的排序规则。
您可以使用COLLATE子句将字符表达式应用于 某些整理。字符文字和变量被赋值 当前数据库的默认排序规则。列引用是 分配了列的定义排序规则。
参考文献:
COLLATE