更改SQL Server数据库排序 [英] Changing SQL Server Database sorting

查看:63
本文介绍了更改SQL Server数据库排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个更改SQL Server数据库排序规则的请求:

I have a request to change the collation of a SQL Server Database:


ALTER DATABASE solarwind95
整理SQL_Latin1_General_CP1_CI_AS

ALTER DATABASE solarwind95 collate SQL_Latin1_General_CP1_CI_AS

但是我遇到这个奇怪的错误:

but I get this strange error:


Meldung 5075,Ebene 16,Status 1,
Zeile 1 Das'Spalte'-Objekt
'CustomPollerAssignment.PollerID'ist
von'Datenbanksortierung'abhängig。
Die Datenbanksortierung kann nicht
geändertwerden,wenn ein
schemagebundenes Objekt von ihr
abhängigist。 Entfernen Sie die
Anhängigkeitender
Datenbanksortierung和wiederholen
Sie den Vorgang。

Meldung 5075, Ebene 16, Status 1, Zeile 1 Das 'Spalte'-Objekt 'CustomPollerAssignment.PollerID' ist von 'Datenbanksortierung' abhängig. Die Datenbanksortierung kann nicht geändert werden, wenn ein schemagebundenes Objekt von ihr abhängig ist. Entfernen Sie die Anhängigkeiten der Datenbanksortierung, und wiederholen Sie den Vorgang.

对不起德国错误消息。我不知道如何将语言切换为英语,但这是翻译:

Sorry for the german errror message. I do not know how to switch the language to english, but here is a translation:


翻译:消息5075,第16层,
状态1,行1列对象
CustomPollerAssignment.PollerID
取决于数据库排序。如果架构绑定对象
依赖数据库排序,则
数据库排序不能更改。
删除数据库
sortieren的依赖项并重试。

Translation: Message 5075, Layer 16, Status 1, Row 1 The 'column' object 'CustomPollerAssignment.PollerID' depends on 'Database sorting. The database sorting cannot be changed if a schema bound object depends on it. Remove the dependency of the database sortieren and retry.

我收到了很多类似的错误

I got a ton more of the errors like that.

推荐答案

您需要将与SCHEMABINDING 删除视图和表值函数。要识别它们,您可以查询 INFORMATION_SCHEMA 视图:

You'll need to remove WITH SCHEMABINDING from your views and table-valued functions. To identify them you can query the INFORMATION_SCHEMA views:

SELECT TABLE_SCHEMA, TABLE_NAME AS VIEW_NAME
FROM INFORMATION_SCHEMA.VIEWS
WHERE VIEW_DEFINITION LIKE '%SCHEMABINDING%'

SELECT ROUTINE_SCHEMA, ROUTINE_NAME
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%SCHEMABINDING%'




  1. 首先备份数据库。

  2. 生成所有绑定到架构的视图和函数的 ALTER 脚本。

  3. 删除单词 与脚本绑定

  4. 运行脚本几次,直到解决所有引用错误。

  5. 更改数据库上的排序规则。

  6. 脚本并删除所有约束(键,检查和默认值)。

  7. 更改以下项的排序规则

  8. 重新创建约束。

  9. 最后,将原始脚本运行几次以可行的模式绑定。

  1. First backup the database.
  2. Generate an ALTER script of all schema-bound views and functions.
  3. Delete the words "WITH SCHEMABINDING" from the script.
  4. Run the script a few times, until all reference errors are resolved.
  5. Change the collation on your database.
  6. Script and drop all constraints (keys, checks and defaults).
  7. Change the collation of each column using the script below.
  8. Recreate constraints.
  9. Finally, run the original script a few times to enable schema-binding.

您可以使用以下脚本更改所有列的排序规则:

You can change the collation of all columns with this script:

DECLARE @collation nvarchar(128)
DECLARE @commands table ([SQL] nvarchar(max))
DECLARE @cursor cursor
DECLARE @sql nvarchar(max)

SET @collation = 'SQL_Latin1_General_CP1_CI_AS'

INSERT @commands ([SQL])
SELECT 'ALTER TABLE ' + QUOTENAME(c.TABLE_SCHEMA) +'.'+ QUOTENAME(c.TABLE_NAME)
    + ' ALTER COLUMN ' + QUOTENAME(c.COLUMN_NAME)
    + ' ' + c.DATA_TYPE
    + ISNULL('(' + LTRIM(STR(c.CHARACTER_MAXIMUM_LENGTH)) + ')', '')
    + ISNULL(' COLLATE ' + @collation, '')
    + ' ' + CASE c.IS_NULLABLE WHEN 'NO' THEN 'NOT ' ELSE '' END + 'NULL'
FROM INFORMATION_SCHEMA.COLUMNS c
INNER JOIN INFORMATION_SCHEMA.TABLES t
ON t.TABLE_SCHEMA = c.TABLE_SCHEMA AND t.TABLE_NAME = c.TABLE_NAME
WHERE t.TABLE_TYPE = 'BASE TABLE'
AND c.COLLATION_NAME <> @collation

SET @cursor = CURSOR FOR SELECT [SQL] FROM @commands
OPEN @cursor
FETCH NEXT FROM @cursor INTO @sql

WHILE @@FETCH_STATUS = 0
BEGIN 
    PRINT @sql
    EXEC (@sql)

    FETCH NEXT FROM @cursor INTO @sql
END

这篇关于更改SQL Server数据库排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆