下面将为您介绍可以实现将sql server表改为dbo的语句写法,供您参考,如果您对sql server表方面感兴趣的方法,不妨一看 。
- 01 --执行这个语句,就可以把当前库的所有表的所有者改为dbo
-
- 02 exec sp_msforeachtable sp_changeobjectowner ?, dbo
-
- 03
-
- 04
-
- 05 --如果是要用户表/存储过程/视图/触发器/自定义函数一齐改,则用游标(不要理会错误提示)
-
- 06 declare tb cursor local for
-
- 07 select sp_changeobjectowner [+replace(user_name(uid),],]])+].[+replace(name,],]])+],dbo
-
- 08 from sysobjects
-
- 09 where xtype in(U,V,P,TR,FN,IF,TF) and status>=0
-
- 10 open tb
-
- 11 declare @s nvarchar(4000)
-
- 12 fetch tb into @s
-
- 13 while @@fetch_status=0
-
- 14 begin
-
- 15 exec(@s)
-
- 16 fetch tb into @s
-
- 17 end
-
- 18 close tb
-
- 19 deallocate tb
-
- 20 go
以SA登陆查询分析器 ,选中你要的数据库
执行存储过程
执行exec Changename ‘原所有者,dbo
或exec Changename ‘dbo,数据库所有者 IT技术网Www.ofAdmin.Com
修改MS SQL表用户属性的命令
可以用exec sp_changeobjectowner ‘dataname.数据表,dbo 把表或存储过程中的所有者都改成dbo 。