把mssql server所有表的所有者改为dbo
作者:蛛蛛虎 日期:2010-07-22
解决办法:
将当前库的所有表的所有者改为dbo后一切正常:
复制内容到剪贴板
程序代码
程序代码exec sp_msforeachtable 'sp_changeobjectowner ''?'', ''dbo'''
以SA登陆查询分析器,选中你要的数据库,执行上述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
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
上一篇: SQL实现上一条下一条记录查询
下一篇: Microsoft VBscript 运行时错误 错误 '800a0046' 没有权限
文章来自: 本站原创
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: -
发表评论

