RSS 2.0 | Atom 1.0 | CDF

Search

Categories

Archive

Blogroll

Sign In

# Sunday, January 16, 2005
Sunday, January 16, 2005 6:37:40 PM (GMT Standard Time, UTC+00:00) ( Database )

Tibor Karaszi showed how to do this time saving technique on a newsgroup post. You can use the sp_changeobjectowner stored procedure in the Master database to change the owner of an object one at a time, but there is a semi-automatic way to do it.

Open query analyser, change the selected database to the on you want to work on. The following query generates a list of exec commands for all the sprocs and UDFs in the database:


SELECT 'EXEC sp_changeobjectowner ''dbo.' + ROUTINE_NAME + ''', ''thenewuser'''
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_SCHEMA = 'dbo'

Execute it, then click the top left corner of the output window, to select all the rows. Copy and paste the rows into a new query window and execute.

To change table owners, modify the query and repeat the proces:

SELECT 'EXEC sp_changeobjectowner ''dbo.' + TABLE_NAME + ''', ''thenewuser'''
FROM INFORMATION_SCHEMA.TABLES
Comments [2] | | # 
Thursday, July 14, 2005 2:07:20 PM (GMT Daylight Time, UTC+01:00)
Hey, just found this browsing around. really helped me save time from changing the table owner one at a time.

Thanks
Monday, October 22, 2007 3:53:54 PM (GMT Daylight Time, UTC+01:00)
Thanks a ton for this, saved me a bunch of time.
Josh
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview