sp_changedbowner (Transact-SQL)sp_changedbowner (Transact-SQL)

适用对象:是SQL Server 否Azure SQL 数据库 否Azure Synapse Analytics (SQL DW) 否并行数据仓库 APPLIES TO: yesSQL Server noAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

更改当前数据库的所有者。Changes the owner of the current database.

重要

此功能处于维护模式并且可能会在 Microsoft SQL Server 将来的版本中被删除。This feature is in maintenance mode and may be removed in a future version of Microsoft SQL Server. 请避免在新的开发工作中使用该功能,并着手修改当前还在使用该功能的应用程序。Avoid using this feature in new development work, and plan to modify applications that currently use this feature.改为使用ALTER AUTHORIZATIONUse ALTER AUTHORIZATION instead.

主题链接图标 Transact-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

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

参数Arguments

[ @loginame= ]"login"[ @loginame= ] 'login'
当前数据库的新所有者的登录 ID。Is the login ID of the new owner of the current database. loginsysname为,无默认值。login is sysname, with no default. 登录名必须是现有SQL ServerSQL Server的登录名或 Windows 用户。login must be an already existing SQL ServerSQL Server 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[ @map= ] remap_alias_flag
Remap_alias_flag参数已弃用,因为已从中SQL ServerSQL Server删除登录别名。The remap_alias_flag parameter is deprecated because login aliases have been removed from SQL ServerSQL Server. 使用remap_alias_flag参数不会导致错误,但不会产生任何影响。Using the remap_alias_flag parameter does not cause an error but has no effect.

返回代码值Return Code Values

0(成功)或 1(失败)0 (success) or 1 (failure)

备注Remarks

执行 sp_changedbowner 之后,新所有者称为数据库中的 dbo 用户。After sp_changedbowner is executed, the new owner is known as the dbo user inside the database. dbo 拥有执行数据库中所有活动的暗示性权限。The dbo has implied permissions to perform all activities in the database.

不能更改 master、model 或 tempdb 系统数据库的所有者。The owner of the master, model, or tempdb system databases cannot be changed.

若要显示有效登录值的列表,请执行 sp_helplogins 存储过程。To display a list of the valid login values, execute the sp_helplogins stored procedure.

仅通过登录参数执行 sp_changedbowner 会将数据库所有权更改为登录名Executing sp_changedbowner with only the login parameter changes database ownership to login.

使用 ALTER AUTHORIZATION 语句可以更该任意安全对象的所用者。You can change the owner of any securable by using the ALTER AUTHORIZATION statement. 有关详细信息,请参阅 ALTER AUTHORIZATION (Transact-SQL)For more information, see ALTER AUTHORIZATION (Transact-SQL).

权限Permissions

要求具有对数据库的 TAKE OWNERSHIP 权限。Requires TAKE OWNERSHIP permission on the database. 如果新所有者在数据库中具有对应的用户,则要求具有对登录名的 IMPERSONATE 权限,否则要求具有对服务器的 CONTROL SERVER 权限。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

以下示例将登录名 Albert 设为当前数据库的所有者。The following example makes the login Albert the owner of the current database.

EXEC sp_changedbowner 'Albert';  

另请参阅See Also

安全存储过程 (Transact-sql) Security Stored Procedures (Transact-SQL)
CREATE DATABASE (SQL Server Transact-SQL) CREATE DATABASE (SQL Server Transact-SQL)
sp_dropalias (Transact-sql) sp_dropalias (Transact-SQL)
sp_dropuser (Transact-sql) sp_dropuser (Transact-SQL)
sp_helpdb (Transact-sql) sp_helpdb (Transact-SQL)
sp_helplogins (Transact-sql) sp_helplogins (Transact-SQL)
系统存储过程 (Transact-SQL)System Stored Procedures (Transact-SQL)