无法更新 sys.columns - 还有其他方法吗?
我刚刚发现,由于我在具有不同排序规则的不同服务器上创建了数据库,然后迁移到具有新排序规则的新服务器,现在我继续遇到麻烦,我决定更改旧排序规则的所有值。
所以我尝试执行这个查询:
sp_configure "Allow Updates", 1
GO
RECONFIGURE WITH OVERRIDE
GO
UPDATE sys.columns SET collation_name =
'SQL_Latin1_General_CP1_CI_AS' WHERE collation_name = 'Hebrew_CI_AS'
GO
sp_configure "Allow Updates", 0
GO
RECONFIGURE
GO
但这里是查询的输出:
Configuration option 'allow updates' changed from 0 to 1.
Run the RECONFIGURE statement to install.
Msg 259, Level 16, State 1, Line 2
Ad hoc updates to system catalogs are not allowed.
Configuration option 'allow updates' changed from 1 to 0.
Run the RECONFIGURE statement to install.
UPDATE
根据下面的答案,我只是在寻找一种自动化的方式来执行该操作。
I just found out, that since I created my DB on a different server that had a different collation, then immigrated to a new server with new collation, now I keep on having trouble, and I decided to change all the values of the old collation.
So I tried to execute this query:
sp_configure "Allow Updates", 1
GO
RECONFIGURE WITH OVERRIDE
GO
UPDATE sys.columns SET collation_name =
'SQL_Latin1_General_CP1_CI_AS' WHERE collation_name = 'Hebrew_CI_AS'
GO
sp_configure "Allow Updates", 0
GO
RECONFIGURE
GO
But here is the output of the query:
Configuration option 'allow updates' changed from 0 to 1.
Run the RECONFIGURE statement to install.
Msg 259, Level 16, State 1, Line 2
Ad hoc updates to system catalogs are not allowed.
Configuration option 'allow updates' changed from 1 to 0.
Run the RECONFIGURE statement to install.
UPDATE
According to the answers bellow, I am just looking for an automated way to perform the action.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要发出 ALTER TABLE 命令才能更改特定列的排序规则。
例如,
查看此 MSDN 参考
You need to issue ALTER TABLE commands in order to change the collations of the specific columns.
e.g.
Check out this MSDN reference
您可以使用
alter table
更改每列的排序规则。更改数据库排序规则的唯一方法是删除并重新创建数据库。
You can use
alter table
to change the collation for each column.The only way to change a database collation is to drop and recreate the database.
此查询生成一个脚本,该脚本会将所有
Hebrew_CI_AS
排序列交换为Latin1_General_CI_AS
排序规则:注意: 对于索引/约束的列,您将需要手动编辑,但这也是因为执行上述查询时错误结果(对于约束等)包含表 &列名称,您必须承认它仍然比手动完成所有操作要好。
This query is generates a script that will swap all
Hebrew_CI_AS
collated columns toLatin1_General_CI_AS
collation:NOTE: For columns that are indexed/constrained you'll need to edit manually, but that's also something since when executing the above query the error-result (for a constraint etc.) contains the table & column name, you must admit it's still better than do everything manually.