2011-03-20 5 views
2

에서 SQL_Latin1_General_CP1_CI_AS으로 AdventureWorks 데이터베이스의 데이터 정렬을 변경해야합니다. 아무도 그것을하는 방법을 알고 있습니까? 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 

을 그러나 나는 다음과 같은 오류 있어요 :

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 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.

내가하려고했던 무언가를

Msg 4104, Level 16, State 1, Line 10
The multi-part identifier "U.Name" could not be bound.

AdventureWorks 데이터베이스에 대해이 마지막 쿼리를 실행하려고했는데 위와 같이 U.Name 이름 오류가 발생했으며 master 데이터베이스에 대해이 쿼리를 실행할 때 아무 일도 발생하지 않았습니다.

도와주세요!

+0

AdventureWorks와 스크립트에서 오류가 발생하는 이유는 대/소문자를 구분하여 'U'와 'u'가 동일하지 않기 때문입니다. 이러한 문제를 해결하고 다시 시도하면 어떻게됩니까? 마스터의 데이터 정렬을 변경하는 유일한 방법은 데이터를 다시 작성하는 것입니다. –

+0

이 U 문제를 해결할 때 다음과 같이 나타납니다. 메시지 102, 수준 15, 상태 1, 줄 1 '근처에 구문이 잘못되었습니다. :( – truthseeker

+0

) @Size = -1 일 때'convert (varchar, @ Size)'는 'else'로 변환해야합니다. DB가 아닌 열. 문제가되는 제약 조건 등을 제거하고 ** 데이터베이스 ** 데이터 정렬을 변경하고 다시 추가해야합니다. –

답변

2

처음부터 다시 시작하도록 제안하십시오. 위의 방법과 비교하면 노력이 줄어 듭니다.

new copy/scripts for SQL Server 2005 AdventureWorks을 다운로드하십시오.

서버에 기본적으로 원하는 데이터 정렬이 있는지 확인하십시오. 오른쪽 클릭 - Properties-> General-> Server Collation을 클릭하십시오.

SQL Server Management Studio로 데이터베이스를 만들 때 명시 적으로 데이터 정렬을 선택할 수 있습니다.

+0

하지만 설치 구성 요소가 있다는 페이지에 스크립트가 없나요? 아니면 내가 그럴 수 있습니까? :( – truthseeker

+0

올바른 대답은 새로운 설치를 사용하는 것입니다. CI 접미사가있는 파일 (AdventureWorksDBCI.msi) !! – truthseeker