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:
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!
really i searched for entire day around 4 hrs at last i got the solution here, thanks
sweet thanks! saved me some time.
googled for: change owner on all tables
and found you.
great. the tip about changing owner of all tables saved a lot of time.
forgot to say thanks :)
Thanks. Very helpful.
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