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)
DECLE CUROBJECT CURSOR for SELECT NAME = Name, Owner = user_name (uid) from sysobjects where user_name (uid) = @ Oldowner ORDER BY NAME
OPEN curObjectFETCH NEXT FROM curObject INTO @Name, @OwnerWHILE (@@ FETCH_STATUS = 0) BEGIN if @ Owner = @ OldOwner begin set @OwnerName = @OldOwner '.' Rtrim (@Name) exec sp_changeobjectowner @OwnerName, @NewOwner end
Fetch next from curobject @Name, @Ownerend
Close Curobjectdeallocate CurobjectGO
Exec ChangeObjectowner Ro, DBO