更改存储过程的所有者:

declare tb cursor local for
select 'sp_changeobjectowner ''['+replace(user_name(uid),']',']]')+'].['
+replace(name,']',']]')+']'',''dbo'''
from sysobjects
where xtype in('U','V','P','TR','FN','IF','TF') and status>=0
open tb
declare @s nvarchar(4000)
fetch tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch tb into @s
end
close tb
deallocate tb
go

 

更改表的所有者:

exec sp_MSforeachtable 'exec sp_changeobjectowner "?","dbo"'

 

=============

运行时,会提示出错警告,不管它,再运行一次即可。

posted on 2010-01-26 14:56  cean  阅读(305)  评论(0编辑  收藏  举报