欢迎光临
我们一直在努力

更改数据库所有者的对象-数据库专栏,SQL Server

建站超值云服务器,限时71元/月

–功能说明:成批更改数据库所有者的对象
–作者:不详
–用法:exec changeobjectowner nmkspro,dbo
–即可将所有nmkspro所有者的对象改为dbo所有
–运行成功后将提示:”注意: 更改对象名的任一部分都可能破坏脚本和存储过程。”
create procedure dbo.changeobjectowner
 @oldowner as nvarchar(128),–参数原所有者
 @newowner as nvarchar(128)–参数新所有者
as

declare @name   as nvarchar(128)
declare @owner  as nvarchar(128)
declare @ownername as nvarchar(128)

declare curobject cursor for
 select name   = name,
  owner   = user_name(uid)
 from sysobjects
 where user_name(uid)=@oldowner
 order by name

open  curobject
fetch next from curobject into @name, @owner
while(@@fetch_status=0)
begin     
 if @owner=@oldowner
 begin
  set @ownername = @oldowner + . + rtrim(@name)
  exec sp_changeobjectowner @ownername, @newowner
 end

 fetch next from curobject into @name, @owner
end

close curobject
deallocate curobject
go

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 更改数据库所有者的对象-数据库专栏,SQL Server
分享到: 更多 (0)