sp_dropuser (Transact-SQL)sp_dropuser (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

从当前数据库中删除数据库用户。Removes a database user from the current database. sp_dropuser提供与早期版本的兼容性SQL ServerSQL Serversp_dropuser provides compatibility with earlier versions of SQL ServerSQL Server.

重要

此功能处于维护模式并且可能会在 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. 使用DROP USER相反。Use DROP USER instead.

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

语法Syntax

  
sp_dropuser [ @name_in_db = ] 'user'  

参数Arguments

[ @name_in_db = ] 'user' 是要删除的名称。[ @name_in_db = ] 'user' Is the name of the user to remove. 用户sysname,无默认值。user is a sysname, with no default. 用户必须存在于当前数据库。user must exist in the current database. 指定 Windows 登录时,请使用数据库用于标识该登录的名称。When specifying a Windows login, use the name by which the database knows that login.

返回代码值Return Code Values

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

备注Remarks

sp_dropuser执行sp_revokedbaccess以从当前数据库中删除用户。sp_dropuser executes sp_revokedbaccess to remove the user from the current database.

使用sp_helpuser以显示可以从当前数据库中删除的用户名称的列表。Use sp_helpuser to display a list of the user names that can be removed from the current database.

删除数据库用户时,将同时删除该用户的所有别名。When a database user is removed, any aliases to that user are also removed. 如果此用户拥有一个与用户同名的空架构,则此架构也将被删除。If the user owns an empty schema with the same name as the user, the schema will be dropped. 如果用户在数据库中拥有其他任何安全对象,则不会删除该用户。If the user owns any other securables in the database, the user will not be dropped. 必须首先将对象的所有权转让给其他主体。Ownership of the objects must first be transferred to another principal. 有关详细信息,请参阅 ALTER AUTHORIZATION (Transact-SQL)For more information, see ALTER AUTHORIZATION (Transact-SQL). 删除数据库用户时,将自动删除与该用户相关联的权限,并且将该用户从其所属的所有数据库角色中删除。Removing a database user automatically removes the permissions associated with that user and removes the user from any database roles of which it is a member.

sp_dropuser不能用于删除数据库所有者 (dbo) INFORMATION_SCHEMA用户,或来宾用户从mastertempdb数据库。sp_dropuser cannot be used to remove the database owner (dbo) INFORMATION_SCHEMA users, or the guest user from the master or tempdb databases. 在非系统数据库EXEC sp_dropuser 'guest'将撤消用户的连接权限来宾In nonsystem databases, EXEC sp_dropuser 'guest' will revoke CONNECT permission from user guest. 但不会删除用户本身。But the user itself will not be dropped.

sp_dropuser不能在用户定义的事务内执行。sp_dropuser cannot be executed within a user-defined transaction.

权限Permissions

需要对数据库具有 ALTER ANY USER 权限。Requires ALTER ANY USER permission on the database.

示例Examples

以下示例从当前数据库中删除用户 AlbertThe following example removes the user Albert from the current database.

EXEC sp_dropuser 'Albert';  
GO  

请参阅See Also

安全存储过程 (Transact-SQL) Security Stored Procedures (Transact-SQL)
sp_grantdbaccess (Transact-SQL) sp_grantdbaccess (Transact-SQL)
DROP USER (Transact-SQL) DROP USER (Transact-SQL)
sp_revokedbaccess (Transact-SQL) sp_revokedbaccess (Transact-SQL)
系统存储过程 (Transact-SQL)System Stored Procedures (Transact-SQL)