更动数据库中表的所属客户的八个措施

dbo –即可将所有nmkspro所有者的对象改为dbo所有,成批更改数据库所有者的对象 –作者,–存储更改全部表,CREATE PROCEDURE dbo.User,批量修改表的所有者,EXEC sp,@NewOwner as NVARCHAR(128)–新所有者,–当前所有者

DECLARE @Name as NVARCHAR(128) DECLARE @Owner as NVARCHAR(128) DECLARE
@OwnerName as NVARCHAR(128)

–改革有个别表
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

删除:

图片 1图片 2Code
CREATE PROCEDURE dbo.ChangeObjectOwner
@CurrentOwner as NVARCHATiggo(128卡塔尔,–当前主人
@NewOwner as NVARCHA奥德赛(128卡塔尔(قطر‎–新全部者
AS 
DECLARE @Name   as NVARCHAR(128) 
DECLARE @Owner as NVARCHAR(128)
DECLARE @OwnerName as NVARCHAR(128) 

大旨提醒:因为部分网址是选取虚构主机.用sql-server导数据上去的话

批量修改存款和储蓄进度的蕴藏进度:

 

DECLARE curObject CURSOR FOR select Name = name, Owner = user_name(uid)
from sysobjects where user_name(uid)=@OldOwner order by name

declare proccur cursor for select [name] from sysobjects where
type=’P’declare @procname varchar(100)open proccurfetch next from
proccur into @procnamewhile(@@FETCH_STATUS = 0卡塔尔begin –exec(‘drop
proc ‘ + @procname卡塔尔国 –本句被疏解,使用时请打消

print(@procname + ‘已被删除’卡塔尔国 fetch next from proccur into
@procnameendclose proccurdeallocate proccur

DECLARE curObject CURSOR FOR 
select ‘Name’   = name,
‘Owner’   = user_name(uid)
from sysobjects
where user_name(uid)=@CurrentOwner  –and   xtype=’p’
order by name 

FETCH NEXT FROM curObject INTO @Name, @Owner END

批量校正表的全体者: