欢迎光临
我们一直在努力

更改数据库中表的所属用户的两个方法_数据库技巧

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

–更改某个表
exec sp_changeobjectowner tablename,dbo



–存储更改全部表
CREATE PROCEDURE dbo.User_ChangeObjectOwnerBatch
 @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
— select @name,@NewOwner,@OldOwner


 FETCH NEXT FROM curObject INTO @Name, @Owner
END


close curObject
deallocate curObject



GO

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