将sql server所有表的所有者改为dbo

--执行这个语句,就可以把当前库的所有表的所有者改为dbo
exec sp_msforeachtable 'sp_changeobjectowner ''?'', ''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 

以SA登陆查询分析器 ,选中你要的数据库
执行存储过程
执行exec Changename ‘原所有者','dbo'
或exec Changename ‘dbo,'数据库所有者' IT技术网Www.ofAdmin.Com

修改MS SQL表用户属性的命令

IT技术网Www.ofAdmin.Com

可以用exec sp_changeobjectowner ‘dataname.数据表','dbo' 把表或存储过程中的所有者都改成dbo

posted @ 2010-08-14 17:53  仙仙  阅读(1216)  评论(0编辑  收藏  举报