Total Pageviews

Wednesday, September 19, 2012

Change DBOwner


A lot of times people will move a database from one instance to another.  A good example of this is to move a database from production to a test environment.  With SQL 2012, you have partially contained databases that can handle the security requirements for this.  However, a lot of times people attach a database and then have no access to it.  The reason for this, usually, is that the DBOwner of that database does not exist in the new instance.  So, they need to change the DBOwner.  To do this, simply use the sp_changedbowner stored procedure.  Please keep in mind that you must run this command from a user that has the sysadmin fixed server role.


Example:

Use AdventureWorks2012
GO
EXEC sp_changedbowner 'John'


This will make John the DBOwner of the AdventureWorks2012 database.