sp_changedbowner System Stored Procedure

Changes the owner of a database.

Syntax

sp_changedbowner login_id [, true]

where

login_id
Is the login ID of the new owner of the current database. The new owner must not already be known as a user or an alias (that is, the new owner must not already be listed in sysusers or sysalternates). Executing sp_changedbowner with the single parameter login_id changes the database ownership to the login_id and drops the aliases of users who could act as the old database owner.
true
Transfers aliases and their permissions to the new database owner.

Remarks

The sp_changedbowner system stored procedure makes login_id the owner of the current database.

The new database owner must already have a login ID on SQL Server but must not have a database name or alias name in the current database. To assign database ownership to such a user, drop the user's database name and alias entries before executing sp_changedbowner.

After the sp_changedbowner system stored procedure is executed, the new owner is known as the database owner inside the database.

To grant permissions to a user who is the new owner, the system administrator must grant the permissions to the database owner, because the user is known inside the database only by that other name.

Example

This example makes the user Albert the owner of the current database.

sp_changedbowner Albert

Permission

Only the system administrator can execute this procedure.

Tables Used

master.dbo.sysdatabases, master.dbo.syslogins, sysalternates, sysusers

See Also

CREATE DATABASE sp_dropuser
sp_addlogin sp_helpdb
sp_dropalias