风易博客

风萧萧兮易水寒, 壮士一去兮不复还。

« 国内10大域名注册商DB_ONER权限日志备分专用一句话木马 »

更改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


批量更改所有表的用户为dbo

exec sp_msforeachtable 'sp_changeobjectowner ''?'',''dbo'''

更改单个表:

所有者是dbo的表[sitemap],更改所有者为wind88.net

exec sp_changeobjectowner '[dbo].[sitemap]',[wind88.net]


把所有者是wind88.net的表[sitemap],更改所有者为dbo

exec sp_changeobjectowner '[wind88.net].[sitemap]',[dbo]

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Spirit Build 80722 Code detection by Codefense  theme by BokeZhuti

Copyright © 2005 - 2008 风易博客 1982Y.Net.Cn All Rights Reserved.  由Wind88.Net提供优质主机空间
沪ICP备05006417号