declare @OldOwner varchar(100)
declare @NewOwner varchar(100)
set @OldOwner = 'ABC'
set @NewOwner = 'dbo'
--Tables--
select 'EXEC sp_changeobjectowner ''[' + table_schema + '].[' + table_name + ']'', ''' + @NewOwner + ''' '
from information_schema.TABLES
where Table_schema = @OldOwner
--Views--
select 'EXEC sp_changeobjectowner ''[' + table_schema + '].[' + table_name + ']'', ''' + @NewOwner + ''' '
from information_schema.VIEWS
where Table_schema = @OldOwner
--Stored Procedures--
select 'EXEC sp_changeobjectowner ''[' + @OldOwner + '].[' + obj.name + ']'', ''' + @NewOwner + ''' '
from Sys.objects obj
Inner join Sys.schemas sch ON obj.schema_id=sch.schema_id
where [type]='P' AND is_ms_shipped=0 AND sch.[name] = @OldOwner
0 comments:
Post a Comment