Wednesday, March 7, 2012

Change the owner of Model database

Hi
We have a model database that is owned by someone who has left the company.
i would like to change the owner but don't seem to be able to.
sp_changedbowner won't let me.
We have come up with two solutions that I would like to get some comments
on. Any other solutions would be welcome too.
Solution 1
Update the sid in master..sysdatabases to the id of the new owner for model.
Solution 2
Temporarily Change sp_changedbowner to allow an update to model.
i.e. change
Any comments or other solutions?
Cheers Brian
-- CANT CHANGE OWNER OF MASTER/MODEL/TEMPDB --
if db_name() in ('master', 'model', 'tempdb')
begin
raiserror(15109,-1,-1)
return(1)
end
to
-- CANT CHANGE OWNER OF MASTER/TEMPDB --
if db_name() in ('master', 'tempdb')
begin
raiserror(15109,-1,-1)
return(1)
end
Begs the question - how did it get in that state? The sid for those DBs
should always be 0x01, which correlates to the 'sa' login. Both
solutions you suggest are fairly questionable, but it's pretty much a
case of damned if you do, damned if you don't.
Personally, I'd be tempted to hack the sp_changedbowner proc (or rather
copy & paste the code into a new proc (and 'allow updates'
(sp_configure) so the system tables can be updated by our new proc)) to
just take out that restriction for the model database temporarily. That
way you can be sure that all the other things that sp_changedbowner does
(tweaking sysusers, etc.) happens too. But neither method would be
particularly kosher - just make sure you backup master & model before
doing any of this, as you might shoot yourself in the foot if you're not
careful.
Good luck.
*mike hodgson*
blog: http://sqlnerd.blogspot.com
AussieBri wrote:

>Hi
>We have a model database that is owned by someone who has left the company.
>i would like to change the owner but don't seem to be able to.
>sp_changedbowner won't let me.
>We have come up with two solutions that I would like to get some comments
>on. Any other solutions would be welcome too.
>Solution 1
>Update the sid in master..sysdatabases to the id of the new owner for model.
>Solution 2
>Temporarily Change sp_changedbowner to allow an update to model.
>i.e. change
>Any comments or other solutions?
>Cheers Brian
> -- CANT CHANGE OWNER OF MASTER/MODEL/TEMPDB --
> if db_name() in ('master', 'model', 'tempdb')
> begin
> raiserror(15109,-1,-1)
> return(1)
> end
>to
>
> -- CANT CHANGE OWNER OF MASTER/TEMPDB --
> if db_name() in ('master', 'tempdb')
> begin
> raiserror(15109,-1,-1)
> return(1)
> end
>
>

No comments:

Post a Comment