Applies to: SQL Server (all supported versions)
Changes the owner of the current database.
This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Use ALTER AUTHORIZATION instead.
sp_changedbowner [ @loginame = ] 'login' [ , [ @map = ] remap_alias_flag ]
[ @loginame= ] 'login'
Is the login ID of the new owner of the current database. login is sysname, with no default. login must be an already existing SQL Server login or Windows user. login cannot become the owner of the current database if it already has access to the database through an existing user security account within the database. To avoid this, drop the user within the current database first.
[ @map= ] remap_alias_flag
The remap_alias_flag parameter is deprecated because login aliases have been removed from SQL Server. Using the remap_alias_flag parameter does not cause an error but has no effect.
Return Code Values
0 (success) or 1 (failure)
After sp_changedbowner is executed, the new owner is known as the dbo user inside the database. The dbo has implied permissions to perform all activities in the database.
The owner of the master, model, or tempdb system databases cannot be changed.
To display a list of the valid login values, execute the sp_helplogins stored procedure.
Executing sp_changedbowner with only the login parameter changes database ownership to login.
You can change the owner of any securable by using the ALTER AUTHORIZATION statement. For more information, see ALTER AUTHORIZATION (Transact-SQL).
Requires TAKE OWNERSHIP permission on the database. If the new owner has a corresponding user in the database, requires IMPERSONATE permission on the login, otherwise requires CONTROL SERVER permission on the server.
The following example makes the login
Albert the owner of the current database.
EXEC sp_changedbowner 'Albert';
Security Stored Procedures (Transact-SQL)
CREATE DATABASE (SQL Server Transact-SQL)
System Stored Procedures (Transact-SQL)