--更改某個表
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)=@oldowner
order by name
open curobject
fetch next from curobject into @name, @owner
while(@@fetch_status=0)
begin
if @owner=@oldowner
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
更改資料庫所有者的物件
功能說明 成批更改資料庫所有者的物件 declare name as nvarchar 128 declare owner as nvarchar 128 declare ownername as nvarchar 128 declare curobject cursor for select na...
更改資料庫物件的所有者
更改當前資料庫中物件的所有者。語法sp changeobjectowner objname object newowner owner 引數 objname object 當前資料庫中現有的表 檢視或儲存過程的名稱。object 的資料型別為nvarchar 517 沒有預設值。object 可用現...
更改資料庫對像的所有者
libin ftsafe 子陌紅塵 sp changeobjectowner 更改當前資料庫中物件的所有者。語法sp changeobjectowner objname object newowner owner sp changedbowner 更改當前資料庫的所有者。語法sp changedbo...