Friday, 25 January 2013

Alter schema name for whole database stored procedures using cursor


SELECT 'ALTER SCHEMA dbo TRANSFER ' + s.Name + '.' + p.Name FROM
sys.Procedures p INNER JOIN sys.Schemas s on p.schema_id = s.schema_id
where s.Name = 'ebiz1'

declare @ProcName varchar(500)
declare cur cursor
for SELECT 'ALTER SCHEMA dbo TRANSFER ' + s.Name + '.' + p.Name FROM sys.Procedures p INNER JOIN sys.Schemas s on p.schema_id = s.schema_id where s.Name = 'ebiz1'
open cur
fetch next from cur into @ProcName
while @@fetch_status = 0
begin
begin try
exec (@ProcName)
end try
begin catch
 select ERROR_MESSAGE() as ErrorMessage
end catch
 fetch next from cur into @ProcName
end
close cur
deallocate cur

No comments:

Post a Comment