Wednesday, March 7, 2012

Changing owner of DB objects

I have a database where all objects within it and owned by a user not dbo.
Is there any way I can change all the object ownerships to dbo? I'm talking
thousands of objects so I'm thinking some form of script.
thanks
GavGav
SELECT 'EXEC sp_changeobjectowner '''+ROUTINE_NAME+''',''dbo'''
FROM INFORMATION_SCHEMA.ROUTINES
WHERE OBJECTPROPERTY(OBJECT_ID(ROUTINE_SCHEMA+'.'+ROUTINE_NAME),
'IsMsShipped')=0
AND ROUTINE_SCHEMA != 'dbo'
"Gav" <gav@.nospam.com> wrote in message
news:455c2cce$0$696$88260bb3@.news.teranews.com...
>I have a database where all objects within it and owned by a user not dbo.
>Is there any way I can change all the object ownerships to dbo? I'm talking
>thousands of objects so I'm thinking some form of script.
> thanks
> Gav
>|||What version of SQL Server?
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Gav" <gav@.nospam.com> wrote in message news:455c2cce$0$696$88260bb3@.news.teranews.com...
>I have a database where all objects within it and owned by a user not dbo. Is there any way I can
>change all the object ownerships to dbo? I'm talking thousands of objects so I'm thinking some form
>of script.
> thanks
> Gav
>|||Sorry, forgot the obvious. :o) 2000 SP3a.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:eVnJq0WCHHA.3604@.TK2MSFTNGP03.phx.gbl...
> What version of SQL Server?
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "Gav" <gav@.nospam.com> wrote in message
> news:455c2cce$0$696$88260bb3@.news.teranews.com...
>>I have a database where all objects within it and owned by a user not dbo.
>>Is there any way I can change all the object ownerships to dbo? I'm
>>talking thousands of objects so I'm thinking some form of script.
>> thanks
>> Gav
>|||See Uri's post (sp_changeobjectowner).
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Gav" <gav@.nospam.com> wrote in message news:455c42c8$0$709$88260bb3@.news.teranews.com...
> Sorry, forgot the obvious. :o) 2000 SP3a.
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in message
> news:eVnJq0WCHHA.3604@.TK2MSFTNGP03.phx.gbl...
>> What version of SQL Server?
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://www.solidqualitylearning.com/
>>
>> "Gav" <gav@.nospam.com> wrote in message news:455c2cce$0$696$88260bb3@.news.teranews.com...
>>I have a database where all objects within it and owned by a user not dbo. Is there any way I can
>>change all the object ownerships to dbo? I'm talking thousands of objects so I'm thinking some
>>form of script.
>> thanks
>> Gav
>>
>

No comments:

Post a Comment