我的天空(I Like the feeling)

导航

批量修改数据库中某个特定的SCHEMA到另外一个SCHEMA

use yourDB
Go
declare @name sysname
declare @OldSchemaName nvarchar(50);--Old Schema
declare @NewSchemaName nvarchar(50);--New Schema;
set @OldSchemaName='XXXXXXX'
set @NewSchemaName='dbo'
declare csr1 cursor

for

select table_name from information_schema.tables where table_schema=@OldSchemaName;


open csr1


fetch next from csr1 into @name

while (@@fetch_status=0)


begin

set @name=@OldSchemaName+'.' + @name

exec ('alter schema '+@NewSchemaName+' transfer ' + @name)

fetch next from csr1 into @name

end


close csr1

deallocate csr1

 

posted on 2009-11-26 14:06  TBLANK  阅读(261)  评论(0编辑  收藏  举报