当前位置: 首页 > 图文教程 > 数据库 > MSSQL > SQL Server中两种修改对象所有者的方法

MSSQL
SQL Server 索引结构及其使用(一)
SQL中查询数据表字段名称的查询语句
SQL Server 索引结构及其使用(二)
SQL技巧:使用SQL子选择来合并查询
如何恢复/修复MS SQL数据库的MDF文件
获取SQL Server元数据的几种方法
在SQL Server中通过原子建立分子查询
保护SQL Server数据库的十个步骤介绍
SQL Server数据库崩溃后的恢复方法简介
SQL Server与Oracle、DB2的性能比较
SQL Server中用索引视图查看性能状况
利用SQL Server系统函数进行代码存档
将 MS SQL Server 2005 SP2 整合到安装文件
如何改进SQL Server安全系统
SQL Server管理常用的SQL和T-SQL简介
精华推荐:SQL Server的用户及权限
Sql server 如何得到汉字的声母
sql server中order by部分使用方式
在SQLServer中用XQuery分解XML数据
两个sql server 2000的通用分页存储过程

MSSQL 中的 SQL Server中两种修改对象所有者的方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 37 ::
收藏到网摘: n/a

一般开发,SQL Server的数据库所有者为dbo.但是为了安全,有时候可能把它换成其它的名称,所有者变换不是很方便.这里列出两种供参考 。

一:

---******************更改权限以添加HHRC用户*************************

--step1 添加第三方用户,如"chn"

--step2 运行sql,加对象权限移至第三方用户

--step3 添加hhrc用户

--step4 运行sql,将对象权限移至hhrc用户

declare @tblname varchar(30)

declare @tblown varchar(50)

declare tbl_cur cursor for

select name from sysobjects where uid='5' and status>=0 and xtype in ('U','P')

--select * from sysusers

open tbl_cur

fetch next from tbl_cur into @tblname

while @@fetch_status=0

begin

set @tblown='web56433.'+@tblname

EXEC sp_changeobjectowner @tblown, 'chn'

print @tblname

fetch next from tbl_cur into @tblname

end

close tbl_cur

deallocate tbl_cur
 
第二种.

--手动修改系统表

--设备可以手动修改表

exec sp_configure 'allow updates',1
RECONFIGURE WITH OVERRIDE
 
--更改对象所有者

update sysobjects set uid = 1 where uid = 5

update sysobjects set uid = 5 where uid = 1 AND xtype != 'S'

update sysobjects set uid = 1 where name = 'syssegments'

update sysobjects set uid = 1 where name = 'sysconstraints'

exec sp_configure 'allow updates',0

RECONFIGURE WITH OVERRIDE