所面臨的挑戰是要改變排序規則AdventureWorks
數據庫從Latin1_General_CS_AS
到SQL_Latin1_General_CP1_CI_AS
。有誰知道該怎麼做?如何在SQL Server 2005上更改AdventureWorks數據庫排序規則?
我嘗試這樣做:
alter database AdventureWorks set single_user
alter database AdventureWorks collate SQL_Latin1_General_CP1_CI_AS
alter database AdventureWorks set multi_user
但我得到以下錯誤:
Msg 5075, Level 16, State 1, Line 3
The object 'ufnLeadingZeros' 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 5075, Level 16, State 1, Line 3
The object 'CK_ProductReview_Rating' 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 5075, Level 16, State 1, Line 3
The object 'CK_TransactionHistory_TransactionType' 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 5075, Level 16, State 1, Line 3
The object 'CK_ProductVendor_AverageLeadTime' 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.
然後我試圖這樣的事情:
DECLARE @NewCollation VARCHAR(255), @DBName sysname
SELECT @NewCollation = 'SQL_Latin1_General_CP1_CI_AS', -- change this to the collation that you need
@DBName = DB_NAME()
DECLARE @CName varchar(255),
@TbleName sysname,
@objOwner sysname,
@Sql varchar(8000),
@Size int,
@Status tinyint,
@Colorder int
Declare CurWhileLoop cursor read_only forward_only local
for Select
QUOTENAME(C.Name)
,T.Name
,QUOTENAME(U.Name) + '.' +QUOTENAME(O.Name)
,C.Prec
,C.isnullable
,C.colorder
From syscolumns C
inner join systypes T on C.xtype=T.xtype
inner join sysobjects O on C.ID=O.ID
inner join sysusers u on O.uid = u.uid
where T.Name in ('varchar', 'char', 'text', 'nchar', 'nvarchar', 'ntext')
and O.xtype in ('U')
and C.collation != @NewCollation
and objectProperty(O.ID, 'ismsshipped')=0
order by 3, 1
open CurWhileLoop
SET XACT_ABORT ON
begin tran
fetch CurWhileLoop into @CName, @TbleName, @objOwner, @Size, @Status, @Colorder
while @@FETCH_STATUS =0
begin
set @Sql='ALTER TABLE '[email protected]+' ALTER COLUMN '[email protected]+' '[email protected]+ isnull ('('
+convert(varchar,@Size)+')', '') +' COLLATE '+ @NewCollation
+' '+case when @Status=1 then 'NULL' else 'NOT NULL' end
exec(@Sql) -- change this to print if you need only the script, not the action
fetch CurWhileLoop into @CName, @TbleName, @objOwner, @Size, @Status, @Colorder
end
close CurWhileLoop
deallocate CurWhileLoop
commit tran
而且我得到了以下錯誤:
Msg 4104, Level 16, State 1, Line 10
The multi-part identifier "U.Name" could not be bound.
我試圖對AdventureWorks
數據庫運行這最後詢問和我U.Name名稱錯誤如上,當我試圖運行對主數據庫什麼都不會發生此查詢。
請幫忙!
原因在你對AdventureWorks的腳本錯誤是'U'和'u'不是在一個區分大小寫的排序規則相同。如果您解決這些問題並重試,該怎麼辦?更改'master'的排序規則的唯一方法是重建它。 – 2011-03-20 20:56:53
當我修復這個問題時,我得到了這個: Msg 102,Level 15,State 1,Line 1 ')'附近的語法不正確。 :( – truthseeker 2011-03-20 21:09:30
'convert(varchar,@ Size)'應該是'case when @Size = -1 THEN'Max'else convert(varchar,@ Size)end'注意這個**仍然**只改變整理列不是數據庫,但你也需要放棄問題約束等,改變**數據庫**排序規則並將其添加回去。 – 2011-03-20 21:18:11