DROP USER (Transact-SQL)DROP USER (Transact-SQL)

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

从当前数据库中删除用户。Removes a user from the current database.

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

语法Syntax

-- Syntax for SQL Server and Azure SQL Database  
  
DROP USER [ IF EXISTS ] user_name  
-- Syntax for Azure SQL Data Warehouse and Parallel Data Warehouse  
  
DROP USER user_name  

参数Arguments

IF EXISTS IF EXISTS
适用范围SQL ServerSQL ServerSQL Server 2016 (13.x)SQL Server 2016 (13.x)当前版本SQL 数据库SQL Database)。Applies to: SQL ServerSQL Server ( SQL Server 2016 (13.x)SQL Server 2016 (13.x) through current version, SQL 数据库SQL Database).

有条件地删除用户(仅当其已存在时)。Conditionally drops the user only if it already exists.

user_name user_name
指定在此数据库中用于识别该用户的名称。Specifies the name by which the user is identified inside this database.

RemarksRemarks

不能从数据库中删除拥有安全对象的用户。Users that own securables cannot be dropped from the database. 必须先删除或转移安全对象的所有权,才能删除拥有这些安全对象的数据库用户。Before dropping a database user that owns securables, you must first drop or transfer ownership of those securables.

不能删除 guest 用户,但可在除 master 或 tempdb 之外的任何数据库中执行 REVOKE CONNECT FROM GUEST 来撤消它的 CONNECT 权限,从而禁用 guest 用户。The guest user cannot be dropped, but guest user can be disabled by revoking its CONNECT permission by executing REVOKE CONNECT FROM GUEST within any database other than master or tempdb.

注意

从 SQL Server 2005 开始,架构的行为发生了更改。Beginning with SQL Server 2005, the behavior of schemas changed. 因此,假设架构与数据库用户等价的代码不再返回正确的结果。As a result, code that assumes that schemas are equivalent to database users may no longer return correct results. 旧目录视图(包括 sysobjects)不应用于曾使用下列任何 DDL 语句的数据库中:CREATE SCHEMA、ALTER SCHEMA、DROP SCHEMA、CREATE USER、ALTER USER、DROP USER、CREATE ROLE、ALTER ROLE、DROP ROLE、CREATE APPROLE、ALTER APPROLE、DROP APPROLE、ALTER AUTHORIZATION。Old catalog views, including sysobjects, should not be used in a database in which any of the following DDL statements have ever been used: CREATE SCHEMA, ALTER SCHEMA, DROP SCHEMA, CREATE USER, ALTER USER, DROP USER, CREATE ROLE, ALTER ROLE, DROP ROLE, CREATE APPROLE, ALTER APPROLE, DROP APPROLE, ALTER AUTHORIZATION. 在这类数据库中,必须改用新目录视图。In such databases you must instead use the new catalog views. 新的目录视图将采用在 SQL Server 2005 中引入的使主体和架构分离的方法。The new catalog views take into account the separation of principals and schemas that was introduced in SQL Server 2005. 有关目录视图的详细信息,请参阅目录视图 (Transact-SQL)For more information about catalog views, see Catalog Views (Transact-SQL).

权限Permissions

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

示例Examples

以下示例将从 AbolrousHazem 数据库中删除数据库用户 AdventureWorks2012The following example removes database user AbolrousHazem from the AdventureWorks2012 database.

DROP USER AbolrousHazem;  
GO  

另请参阅See Also

CREATE USER (Transact-SQL) CREATE USER (Transact-SQL)
ALTER USER (Transact-SQL) ALTER USER (Transact-SQL)
EVENTDATA (Transact-SQL)EVENTDATA (Transact-SQL)