批量修改数据库中某个特定的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