SQL:改变数据库所有者为dbo:

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
原文地址:https://www.cnblogs.com/janes/p/1581775.html