DROP ROLE (Transact-SQL)DROP ROLE (Transact-SQL)

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是并行数据仓库Parallel Data Warehouseyes并行数据仓库Parallel Data Warehouse适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是并行数据仓库Parallel Data Warehouseyes并行数据仓库Parallel Data Warehouse

从数据库中删除角色。Removes a role from the database.

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

语法Syntax

-- Syntax for SQL Server  
  
DROP ROLE [ IF EXISTS ] role_name  
-- Syntax for Azure Synapse Analytics and Parallel Data Warehouse  

DROP ROLE role_name  

备注

若要查看 SQL Server 2014 及更早版本的 Transact-SQL 语法,请参阅早期版本文档To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.

参数Arguments

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

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

role_namerole_name
指定要从数据库删除的角色。Specifies the role to be dropped from the database.

注解Remarks

无法从数据库删除拥有安全对象的角色。Roles that own securables cannot be dropped from the database. 若要删除拥有安全对象的数据库角色,必须首先转移这些安全对象的所有权,或从数据库删除它们。To drop a database role that owns securables, you must first transfer ownership of those securables or drop them from the database. 无法从数据库删除拥有成员的角色。Roles that have members cannot be dropped from the database. 若要删除拥有成员的角色,必须首先删除角色的成员。To drop a role that has members, you must first remove members of the role.

若要删除数据库角色中的成员,请使用 ALTER ROLE (Transact-SQL)To remove members from a database role, use ALTER ROLE (Transact-SQL).

不能使用 DROP ROLE 删除固定数据库角色。You cannot use DROP ROLE to drop a fixed database role.

在 sys.database_role_members 目录视图中可以查看有关角色成员身份的信息。Information about role membership can be viewed in the sys.database_role_members catalog view.

注意

从 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).

若要删除服务器角色,请使用DROP SERVER ROLE (Transact-SQL)To remove a server role, use DROP SERVER ROLE (Transact-SQL).

权限Permissions

要求对数据库具有 ALTER ANY ROLE 权限、对角色具有 CONTROL 权限或具有 db_securityadmin 中的成员身份。Requires ALTER ANY ROLE permission on the database, or CONTROL permission on the role, or membership in the db_securityadmin.

示例Examples

以下示例从 AdventureWorks2012 数据库中删除数据库角色 purchasingThe following example drops the database role purchasing from the AdventureWorks2012 database.

DROP ROLE purchasing;  
GO  

另请参阅See Also

CREATE ROLE (Transact-SQL) CREATE ROLE (Transact-SQL)
ALTER ROLE (Transact-SQL) ALTER ROLE (Transact-SQL)
主体(数据库引擎) Principals (Database Engine)
EVENTDATA (Transact-SQL) EVENTDATA (Transact-SQL)
sp_addrolemember (Transact-SQL) sp_addrolemember (Transact-SQL)
sys.database_role_members (Transact-SQL) sys.database_role_members (Transact-SQL)
sys.database_principals (Transact-SQL) sys.database_principals (Transact-SQL)
安全函数 (Transact-SQL)Security Functions (Transact-SQL)