--功能说明:成批更改数据库所有者的对象 --作者:不详 --用法: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)[email protected] order by name
open curobject fetch next from curobject into @name, @owner while(@@fetch_status=0) begin if @[email protected] 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 国内最大的酷站演示中心!