Skip to content

Latest commit

 

History

History
91 lines (70 loc) · 4.4 KB

File metadata and controls

91 lines (70 loc) · 4.4 KB
title sp_changedbowner (Transact-SQL) | Microsoft Docs
ms.custom
ms.date 03/14/2017
ms.prod sql-non-specified
ms.prod_service database-engine
ms.service
ms.component system-stored-procedures
ms.reviewer
ms.suite sql
ms.technology
database-engine
ms.tgt_pltfrm
ms.topic language-reference
f1_keywords
sp_changedbowner
sp_changedbowner_TSQL
dev_langs
TSQL
helpviewer_keywords
sp_changedbowner
ms.assetid 516ef311-e83b-45c9-b9cd-0e0641774c04
caps.latest.revision 35
author edmacauley
ms.author edmaca
manager cguyer
ms.workload Active

sp_changedbowner (Transact-SQL)

[!INCLUDEtsql-appliesto-ss2008-xxxx-xxxx-xxx-md]

Changes the owner of the current database.

Important

[!INCLUDEssNoteDepFutureAvoid] Use ALTER AUTHORIZATION instead.

Applies to: [!INCLUDEssNoVersion] ([!INCLUDEssKatmai] through current version).

Topic link icon Transact-SQL Syntax Conventions

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 an already existing [!INCLUDEssNoVersion] 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 [!INCLUDEssNoVersion]. Using the remap_alias_flag parameter does not cause an error but has no effect.

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.

You can change the owner of any securable by using the ALTER AUTHORIZATION statement. For more information, see ALTER AUTHORIZATION (Transact-SQL).

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';  

See Also

Security Stored Procedures (Transact-SQL)
CREATE DATABASE (SQL Server Transact-SQL)
sp_dropalias (Transact-SQL)
sp_dropuser (Transact-SQL)
sp_helpdb (Transact-SQL)
sp_helplogins (Transact-SQL)
System Stored Procedures (Transact-SQL)