--
建儲存過程
create
procedure
changeprocowner
@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
and
xtype='p'
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
fetch
next
from
curobject
into
@name,@owner
end
close
curobject
deallocate
curobjectgo
--執行
exec
changeprocowner
'原所有者'
,'dbo'
SQL儲存過程的所有者修改方法
在你所需要修改儲存過程的資料庫裡新增如下儲存過程,可以直接在查詢分析器裡執行 if exists select from dbo.sysobjects where id object id n dbo changename and objectproperty id,n isprocedure 1 ...
SQL SERVER批量 單個修改表的所有者
通過sql query建立的表,所有者就是執行sql query使用者本身。有時候遷移資料庫之後,使用者更改了,標的所有者也需要更改,不然就會出現讀不到資料的情形。如 mytable物件不存在 之類的。下面是修改表所有者的方式 批量修改 exec sp msforeachtable exec sp ...
修改表的所有者
declare tb cursor local for select sp changeobjectowner replace user name uid replace name,dbo from sysobjects where xtype u and status 0 and user nam...