简体   繁体   English

更改 SQL 2005 中聚集索引列的排序规则

[英]Change collation on clustered index column in SQL 2005

I have a Database that was created with an incorrect collation.我有一个使用不正确的排序规则创建的数据库。 I changed the collation of the database, but this left the individual columns with the incorrect collation also.我更改了数据库的排序规则,但这也使各个列的排序规则不正确。 This causes me a problem.这给我带来了一个问题。

So, I wrote a script to loop through and change the collation of the individual columns and this basically worked, except for a few columns that are part of a clustered index on their respective tables.因此,我编写了一个脚本来循环并更改各个列的排序规则,这基本上是可行的,除了一些列是它们各自表上的聚集索引的一部分。 These I cannot change.这些我无法改变。

For example if I run:例如,如果我运行:

ALTER TABLE MyTable 
ALTER COLUMN MyColumn varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL

I get a response of:我得到以下回复:

Msg 5074, Level 16, State 1, Line 1
The object 'DF_MyTable_MyColumn' is dependent on column 'MyColumn'.
Msg 5074, Level 16, State 1, Line 1
The object 'PK_MyTable_MyColumn_MyOtherColumn' is dependent on column 'MyColumn'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE ALTER COLUMN deleted failed because one or more objects access this column.

Is there any way to work around this to change the collation of these columns?有没有办法解决这个问题来改变这些列的排序规则? I cannot drop the index, obviously, as it forms the Primary Key.显然,我不能删除索引,因为它是 forms 主键。 I suppose I could remove the PK temporarily but I'd rather not.我想我可以暂时删除 PK,但我宁愿不这样做。

You have to remove all dependencies.您必须删除所有依赖项。

When you change the DB collation, you only change the system tables.当您更改数据库排序规则时,您只更改系统表。 All other text-type columns need changed manually.所有其他文本类型的列都需要手动更改。

Generally, MS KB 325335 has options on how to do this for the whole db and all columns通常, MS KB 325335有关于如何为整个数据库和所有列执行此操作的选项

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

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