如何修改SQL Server 中数据库的Collation

来源:互联网 发布:东莞软件开发公司 编辑:程序博客网 时间:2024/06/05 22:47


下面是EntLib.com Team 针对本地数据库subtext --- 修改Collation 的操作过程。

默认情况下,Subtext 数据库的collation 并不是 Chinese_PRC_CI_AS ,下面通过SCRIPT 脚本修改其collation:
ALTER DATABASE SubtextData COLLATE Chinese_PRC_CI_AS

但是,你会遇到如下错误信息:
Msg 5075, Level 16, State 1, Line 1
The object 'iter_charlist_to_table' is dependent on database collation. The database collation cannot be changed if a schema-bound object depends on it. Remove the dependencies on the database collation and then retry the operation.
Msg 5072, Level 16, State 1, Line 1
ALTER DATABASE failed. The default collation of database 'SubtextData' cannot be set to Chinese_PRC_CI_AS.

这是因为修改数据库的collation时,必须满足如下条件:

  • No one else can be using the database.
  • No schema-bound object can be dependent on the database collation. Schema-bound objects include any of the following:
    • User-defined functions and views created with SCHEMABINDING
    • Computed columns
    • CHECK constraints
    • Table-valued functions that return tables with character columns with collations inherited from the default database collation 
       

上述错误提示信息表示存在数据库对象'iter_charlist_to_table'  依赖于数据库的collation,因此无法成功修改数据库subtext的collation。
 
下面进一步查询上述的'iter_charlist_to_table' 对象具体信息:
select * from sys.objects where name='iter_charlist_to_table'

发现 'iter_charlist_to_table'  是一个 Table-valued Function。需要先导出该function 的SQL script脚本,然后删除该function。

这样,ALTER DATABASE SubtextData COLLATE Chinese_PRC_CI_AS  就可以成功执行了。

最后,执行 'iter_charlist_to_table'  导出的脚本,重新创建Table-valued Function 就可以了。

原地址:http://forum.entlib.com/Default.aspx?g=posts&t=285

原创粉丝点击