I have a script like below to change all the object owner from "xxxxx"
to "dbo".
==================================== declare @.name varchar(250)
declare @.olduser varchar(250)
declare @.newuser varchar(250)
declare @.sp_str varchar(250)
set @.olduser = 'xxxxx.'
set @.newuser = 'dbo'
declare cursor1 cursor for
select name from sysobjects where xtype = 'u' and uid = 5 -- (5 - the
uid of 'xxxxx')
open cursor1
fetch next from cursor1 into @.name
WHILE @.@.FETCH_STATUS = 0
--while begin transaction
begin
set @.sp_str = @.olduser + @.name
exec sp_changeObjectOwner @.sp_str,@.newuser
fetch next from cursor1 into @.name
end
--commit transaction
close cursor1
deallocate cursor1
====================================
How if I want to change only a particular database, don't care what's
the existing object owner is, but just change all the object owner to
"xxxxx"?
Does anyone have good script to change that?
Or any way to modify the above script to acomplish that?
Peter CCHChange one line:
select sysobjects.name from sysobjects where sysobjects.xtype = 'u' and
sysobjects.uid NOT IN (SELECT sysusers.uid FROM sysusers WHERE sysusers.name
<> @.newuser)
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Peter CCH" <petercch.wodoy@.gmail.com> wrote in message
news:1133099207.669540.204000@.g14g2000cwa.googlegroups.com...
>I have a script like below to change all the object owner from "xxxxx"
> to "dbo".
> ====================================> declare @.name varchar(250)
> declare @.olduser varchar(250)
> declare @.newuser varchar(250)
> declare @.sp_str varchar(250)
> set @.olduser = 'xxxxx.'
> set @.newuser = 'dbo'
> declare cursor1 cursor for
> select name from sysobjects where xtype = 'u' and uid = 5 -- (5 - the
> uid of 'xxxxx')
> open cursor1
> fetch next from cursor1 into @.name
> WHILE @.@.FETCH_STATUS = 0
> --while begin transaction
> begin
> set @.sp_str = @.olduser + @.name
> exec sp_changeObjectOwner @.sp_str,@.newuser
> fetch next from cursor1 into @.name
> end
> --commit transaction
> close cursor1
> deallocate cursor1
> ====================================> How if I want to change only a particular database, don't care what's
> the existing object owner is, but just change all the object owner to
> "xxxxx"?
> Does anyone have good script to change that?
> Or any way to modify the above script to acomplish that?
>
>
> Peter CCH
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment