随笔 - 87  文章 - 1  评论 - 610  阅读 - 44万

SQL server两种修改对象所有者的方法,

一般开发,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
posted on   edobnet  阅读(2865)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述
< 2005年8月 >
31 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 1 2 3
4 5 6 7 8 9 10

点击右上角即可分享
微信分享提示