Amir Mirkamali RSS 2.0
 Sunday, December 04, 2011
declare 

@NewCollation varchar(255)

,@Stmt nvarchar(4000)

,@DBName sysname

set @NewCollation = 'SQL_Latin1_General_CP1256_CI_AS' -- change this to the collation that you need

set @DBName = DB_NAME()

declare 

@CName varchar(255)

,@TName sysname

,@OName sysname

,@Sql varchar(8000)

,@Size int

,@Status tinyint

,@Colorder int

declare curcolumns 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 curcolumns

SET XACT_ABORT ON

begin tran

fetch curcolumns into @CName, @TName, @OName, @Size, @Status, @Colorder

while @@FETCH_STATUS =0

begin

set @Sql='ALTER TABLE '+@OName+' ALTER COLUMN '+@CName+' '+@TName+ isnull ('('

+CASE @Size WHEN -1 then 'max' else convert(varchar,@Size) end+')', '') +' 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

PRINT @Sql

fetch curcolumns into @CName, @TName, @OName, @Size, @Status, @Colorder

end

close curcolumns

deallocate curcolumns

commit tran
Sunday, December 04, 2011 8:18:44 AM UTC  #    -
SQL Server | Troubleshooting
Archive
<December 2011>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
Blogroll
About the author/Disclaimer

استفاده از مطالب سایت با ذکر منبع آزاد است

© Copyright 2012
Amir Mirkamali

Statistics
Total Posts: 40
This Year: 0
This Month: 0
This Week: 0
Comments: 1
Themes
All Content © 2012, Amir Mirkamali