sp_changedbowner

Transact-SQL Reference

Transact-SQL Reference

sp_changedbowner

Changes the owner of the current database.

Syntax

sp_changedbowner [ @loginame = ] 'login'     [ , [ @map = ] remap_alias_flag ]

Arguments

[@loginame =] 'login'

Is the login ID of the new owner of the current database. login is sysname, with no default. login must be Microsoft® SQL Server™ login or a Microsoft Windows NT® user that already exists. login cannot become the owner of the current database if it already has access to the database through an existing alias or user security account within the database. To avoid this, drop the alias or user within the current database first.

[@map =] remap_alias_flag

Is the value true or false, which indicates whether existing aliases to the old database owner (dbo) are mapped to the new owner of the current database or dropped. remap_alias_flag is varchar(5), with a default of NULL, indicating any existing aliases to the old dbo are mapped to the new owner of the current database. false indicates that existing aliases to the old database owner are dropped.

Return Code Values

0 (success) or 1 (failure)

Remarks

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 and maps the aliases of users who were previously aliased to dbo to the new database owner.

Permissions

Only members of the sysadmin fixed server role or the owner of the current database can execute sp_changedbowner.

Examples

This example makes the user Albert the owner of the current database and maps existing aliases to the old database owner to Albert.

EXEC sp_changedbowner 'Albert'

See Also

CREATE DATABASE

sp_dropalias

sp_dropuser

sp_helpdb

sp_helplogins

System Stored Procedures