Nimble Coder

Adventures in Nimble Coding
posts - 77, comments - 56, trackbacks - 1

Changing table owners in SQL Server

I recently installed some tables via SQL Query Analyzer under a user id that was not 'dbo'. I needed to change the owner on the tables and wrote this simple query to generate the execute statements to change the owner. Run the query to generate the next query -- so you can review the list prior to running it.

SELECT  'exec sp_changeobjectowner ''' + name + ''', ''dbo'''
FROM    sysobjects
WHERE   type = 'U'
    AND uid != 1
ORDER BY name

The result looks something like:

exec sp_changeobjectowner 'asset', 'dbo'
exec sp_changeobjectowner 'project', 'dbo'
exec sp_changeobjectowner 'salesorder', 'dbo'

Print | posted on Sunday, June 03, 2007 2:34 PM | Filed Under [ SQL ]

Feedback

Gravatar

# re: Changing table owners in SQL Server

JK
8/1/2009 6:03 AM | L

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 3 and 5 and type the answer here:

Powered by: