Create proc ChangeObjectOwner
@OldOwner as NVARCHAR(
@NewOwner as NVARCHAR(
AS
DECLARE @Name as NVARCHAR(
DECLARE @Owner as NVARCHAR(
DECLARE @OwnerName as NVARCHAR(
DECLARE curObject CURSOR FOR
select
from sysobjects
where user_name(uid)=@OldOwner
order by name
OPEN curObject
FETCH NEXT FROM curObject INTO @Name
WHILE(@@FETCH_STATUS=
BEGIN
if @Owner=@OldOwner
begin
set @OwnerName = @OldOwner +
exec sp_changeobjectowner @OwnerName
end
FETCH NEXT FROM curObject INTO @Name
END
close curObject
deallocate curObject
GO
From:http://tw.wingwit.com/Article/program/SQL/201311/16270.html