Skip to content

Latest commit

 

History

History
84 lines (58 loc) · 3.16 KB

File metadata and controls

84 lines (58 loc) · 3.16 KB
title sp_changedbowner (Transact-SQL)
description sp_changedbowner changes the owner of the current database.
author VanMSFT
ms.author vanto
ms.reviewer randolphwest
ms.date 06/23/2025
ms.service sql
ms.subservice system-objects
ms.topic reference
f1_keywords
sp_changedbowner
sp_changedbowner_TSQL
helpviewer_keywords
sp_changedbowner
dev_langs
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.

EXECUTE sp_changedbowner 'Albert';

Related content