Skip to content

Latest commit

 

History

History
84 lines (58 loc) · 3.16 KB

sp-changedbowner-transact-sql.md

File metadata and controls

84 lines (58 loc) · 3.16 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs
sp_changedbowner (Transact-SQL)
sp_changedbowner changes the owner of the current database.
VanMSFT
vanto
randolphwest
07/05/2024
sql
system-objects
reference
sp_changedbowner
sp_changedbowner_TSQL
sp_changedbowner
TSQL

sp_changedbowner (Transact-SQL)

[!INCLUDE SQL Server]

Changes the owner of the current database.

Important

[!INCLUDE ssNoteDepFutureAvoid] Use ALTER AUTHORIZATION instead.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

sp_changedbowner
    [ @loginame = ] N'loginame'
    [ , [ @map = ] 'map' ]
[ ; ]

Arguments

[ @loginame = ] N'loginame'

The login ID of the new owner of the current database. @loginame is sysname, with no default. @loginame must be an already existing [!INCLUDE ssNoVersion] login or Windows user. @loginame can't 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 scenario, drop the user within the current database first.

[ @map = ] 'map'

[!INCLUDE deprecated-parameter]

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 user has implied permissions to perform all activities in the database.

The owner of the master, model, or tempdb system databases can't be changed.

To display a list of the valid @loginame values, execute the sp_helplogins stored procedure.

Executing sp_changedbowner with only the @loginame parameter changes database ownership to @loginame.

You can change the owner of any securable by using the ALTER AUTHORIZATION statement. For more information, see ALTER AUTHORIZATION.

Permissions

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.

Examples

The following example makes the login Albert the owner of the current database.

EXEC sp_changedbowner 'Albert';

Related content