Wednesday, October 27, 2004

Change the owner of all tables in SQL Server

(Cambiar el propietario de todas las tablas en SQL Server)

Normally you use sp_changeobjectowner(SQL Server 2000 SP3)

Sample:
Remenber to have the right permissions. In this sample I'm running as dbo and i have logged by using sa

use Northwind
EXECUTE sp_changeobjectowner 'EmployeeTerritory', 'guest'

To take back this, the parameters change a little:

use Northwind
EXECUTE sp_changeobjectowner 'guest.EmployeeTerritory', 'dbo'

Well you must do it for all tables, but using an undocumented Stored Procedure called sp_MSforeachtable you can do this in one line of code:

use Northwind
sp_MSforeachtable @command1="sp_changeobjectowner '?', 'dbo'"

Another undocumented Stored Procedure is sp_MSforeachdb which could be used for change the owner of all Databases

Of course among of this use you can manage to make more interesting things mainly if You are a DBA


Another tip: If you are into the Entreprise Manager seen the data in a table and you want to modify a field an insert null in it, put the cursor in it and press CTRL+0 (Control and zero).


Permalink: Change the owner of all tables in SQL Server 

7 Comments:

At 3:10 AM, Anonymous Anonymous said...

Hey Jose,

From a search on MSN Search, I found your blog entry. This tip about changing the owner on all tables is a life saver for me! Thanks again!

 
At 11:59 AM, Blogger asi schools said...

really i searched for entire day around 4 hrs at last i got the solution here, thanks

 
At 7:00 AM, Anonymous Anonymous said...

sweet thanks! saved me some time.

googled for: change owner on all tables

and found you.

 
At 4:33 PM, Anonymous Anonymous said...

great. the tip about changing owner of all tables saved a lot of time.

 
At 4:33 PM, Anonymous Anonymous said...

forgot to say thanks :)

 
At 9:05 PM, Anonymous Anonymous said...

Thanks. Very helpful.

 
At 8:36 AM, Anonymous Affordable Logo Design said...

This is the post what i was looking for last two weeks .I am glad to find this informative post here in your blog post.Thanks for great stuff.

 

Post a Comment

<< Home