Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Ownership on ALL tables 2

Status
Not open for further replies.

ecobb

Programmer
Dec 5, 2002
2,190
US
Hey,
Is there a command I can run to change the owner of every table in a database? I have a database that was set up with various owners on various tables (someone not knowing what they were doing) and it has over 500 tables it. I'd really rather not go through sp_changeobjectowner on every one of them.

Thanks,

Eric
 
The followig script changes the table owner for all tables in the current database to 'dbo' if not already 'dbo'. The script uses the undocumented system stored procedure sp_msforeachtable.

exec sp_msforeachtable
'If left(''?'',charindex(''.'',''?'')-1)<>''[dbo]''
exec sp_changeobjectowner ''?'',''dbo''' If you want to get the best answer for your question read faq183-874 and faq183-3179.
Terry L. Broadbent - DBA
SQL Server Page:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top