Changing the Database Owner in a SQL Server Database

Changing the Database Owner in a SQL Server Database

Share on Facebook0Share on Google+0Tweet about this on TwitterShare on LinkedIn0Share on Reddit0
In SQL Server 2000, the dbo (Database Owner) is a special user that has all the necessary permissions to perform all activities in the database. This user exists in all SQL Server databases.

Usually, there are SQL Server or Windows logins mapped to the dbo user, thus “inheriting” the permissions of the database’s dbo user and being able to perform all the activities in the database that the dbo user can perform.

In some cases, due to various changes a DBA might perform in SQL Server, you may discover that the dbo user is orphaned, meaning that there is not any login mapped to this user.

If you would like to change this, thus mapping a login to the dbo user you can make use of the “sp_changedbowner” system stored procedure.

The syntax as provided in the T-SQL reference library is the following:

sp_changedbowner [ @loginame= ] ‘login’
[ , [ @map= ] remap_alias_flag ]


For example, if you want to make the SQL Server Login ‘Tom‘ the owner of the database “TestDB” you can use the following T-SQL script:

USE TestDB
GO
EXEC sp_changedbowner ‘Tom’
GO

Additionally, if you want to make a Windows Login, for example ‘SampleDomainTestUser‘ the owner of the database “TestDB” you can use the following T-SQL script:

USE TestDB
GO
EXEC sp_changedbowner ‘SampleDomainTestUser’
GO

Please also note that only members of the sysadmin fixed server role can execute the stored procedure sp_changedbowner.

In SQL Server 2005 or later, you can make use of the “ALTER AUTHORIZATION” command as sp_changedbowner will be removed in a future version of SQL Server.


Recommended eBooks on SQL Server:

Tuning SQL Server: eBook by SQL Server MVP Artemakis Artemiou
Tuning SQL Server: eBook by SQL Server MVP Artemakis Artemiou
Administering SQL Server: eBook by SQL Server MVP Artemakis Artemiou
Administering SQL Server: eBook by SQL Server MVP Artemakis Artemiou
Artemakis Artemiou
Artemakis Artemiou is a Senior SQL Server Architect, Author, Software Developer and a Microsoft Data Platform MVP. He has over 15 years of experience in the IT industry in various roles. Among other, via his initiative SQLEBooks.com, Artemakis authors and publishes eBooks on different topics on SQL Server. Artemakis currently serves as the President of the Cyprus .NET User Group (CDNUG) and the International .NET Association Country Leader for Cyprus (INETA). Additionally he is the founder of the SQLArtBits initiative that aims to provide the technical community with simple, yet powerful and high-quality SQL Server tools. Currently, the highlights of these tools are DBA Security Advisor and In-Memory OLTP Simulator. Artemakis's official website can be found at aartemiou.com. Artemakis's blogs can be found at: SQLNetHub.com and TechHowTos.com.