1.SQL Server中批量更新Object的Owner 2.附加数据库

来自:

http: // www.pconline.com.cn / pcjob / other / data / others / 0611 / 903723_ 3 .html

 

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  
--test
exec  User_ChangeObjectOwnerBatch  ' BMS ' , ' dbo '

 

2、附加数据库:

exec   sp_attach_db   @dbname    =    '' hw '' , @filename1    =    '' c:\hw_data.mdf '' , @filename2    =    '' c:\hw_log.ldf ''   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值