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

–更正有个别表
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

批量去除存款和储蓄进程和批量校订存款和储蓄进程 更正:

FETCH NEXT FROM curObject INTO @Name, @Owner
END 

批量校订: EXEC sp_MSforeachtable exec sp_changeobjectowner ?,dbo
单个改良: exec sp_changeobjectowner 要改的表名,dbo

EXEC sp_MSforeachtable ‘exec sp_changeobjectowner ”?”,”dbo” ‘
单个校正表全数者: exec sp_changeobjectowner ‘要改的表名’,’dbo’

 

FETCH NEXT FROM curObject INTO @Name, @Owner END

再看批量剔除存款和储蓄进度

 

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

–假使二个数据库教程中(表和存款和储蓄进程State of Qatar有多个客商名,而要把它富有都改成dbo
就能够用如下的口舌

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注