--更改某个表
exec sp_changeobjectowner 'tablename','dbo'
--存储更改全部表
create procedure dbo.user_changeobjectownerbatch
@oldowner as nvarchar(128),
@newowner as nvarchar(128)
as
declare @name as nvarchar(128)
declare @owner as nvarchar(128)
declare @ownername as nvarchar(128)
declare curobject cursor for
select 'name' = name,
'owner' = user_name(uid)
from sysobjects
where user_name(uid)[email protected]
order by name
open curobject
fetch next from curobject into @name, @owner
while(@@fetch_status=0)
begin
if @[email protected]
begin
set @ownername = @oldowner + '.' + rtrim(@name)
exec sp_changeobjectowner @ownername, @newowner
end
-- select @name,@newowner,@oldowner
fetch next from curobject into @name, @owner
end
close curobject
deallocate curobject
go
新闻热点
疑难解答