Denies permissions granted on a database user, database role, or application role in SQL Server
Transact-SQL Syntax Conventions
DENY permission [ ,...n ]
ON
{ [ USER :: database_user ]
| [ ROLE :: database_role ]
| [ APPLICATION ROLE :: application_role ]
}
TO <database_principal> [ ,...n ]
[ CASCADE ]
[ AS <database_principal> ]
<database_principal> ::=
Database_user
| Database_role
| Application_role
| Database_user_mapped_to_Windows_User
| Database_user_mapped_to_Windows_Group
| Database_user_mapped_to_certificate
| Database_user_mapped_to_asymmetric_key
| Database_user_with_no_login
permission
Specifies a permission that can be denied on the database principal. For a list of the permissions, see the Remarks section later in this topic.
USER ::database_user
Specifies the class and name of the user on which the permission is being denied. The scope qualifier (::) is required.
ROLE ::database_role
Specifies the class and name of the role on which the permission is being denied. The scope qualifier (::) is required.
APPLICATION ROLE ::application_role
Applies to: SQL Server 2008 through SQL Server 2008 SQL Server 2017 SQL Server 2008 SQL Server 2017 SQL Database
Specifies the class and name of the application role on which the permission is being denied. The scope qualifier (::) is required.
CASCADE
Indicates that the permission being denied is also denied to other principals to which it has been granted by this principal.
AS <database_principal>
Specifies a principal from which the principal executing this query derives its right to revoke the permission.
Database_user
Specifies a database user.
Database_role
Specifies a database role.
Application_role
Applies to: SQL Server 2008 through SQL Server 2008 SQL Server 2017 SQL Server 2008 SQL Server 2017 SQL Database
Specifies an application role.
Database_user_mapped_to_Windows_User
Specifies a database user mapped to a Windows user.
Database_user_mapped_to_Windows_Group
Specifies a database user mapped to a Windows group.
Database_user_mapped_to_certificate
Specifies a database user mapped to a certificate.
Database_user_mapped_to_asymmetric_key
Specifies a database user mapped to an asymmetric key.
Database_user_with_no_login
Specifies a database user with no corresponding server-level principal.
A database user is a database-level securable contained by the database that is its parent in the permissions hierarchy. The most specific and limited permissions that can be denied on a database user are listed in the following table, together with the more general permissions that include them by implication.
Database user permission | Implied by database user permission | Implied by database permission |
---|---|---|
CONTROL | CONTROL | CONTROL |
IMPERSONATE | CONTROL | CONTROL |
ALTER | CONTROL | ALTER ANY USER |
VIEW DEFINITION | CONTROL | VIEW DEFINITION |
A database role is a database-level securable contained by the database that is its parent in the permissions hierarchy. The most specific and limited permissions that can be denied on a database role are listed in the following table, together with the more general permissions that include them by implication.
Database role permission | Implied by database role permission | Implied by database permission |
---|---|---|
CONTROL | CONTROL | CONTROL |
TAKE OWNERSHIP | CONTROL | CONTROL |
ALTER | CONTROL | ALTER ANY ROLE |
VIEW DEFINITION | CONTROL | VIEW DEFINITION |
An application role is a database-level securable contained by the database that is its parent in the permissions hierarchy. The most specific and limited permissions that can be denied on an application role are listed in the following table, together with the more general permissions that include them by implication.
Application role permission | Implied by application role permission | Implied by database permission |
---|---|---|
CONTROL | CONTROL | CONTROL |
ALTER | CONTROL | ALTER ANY APPLICATION ROLE |
VIEW DEFINITION | CONTROL | VIEW DEFINITION |
Requires CONTROL permission on the specified principal, or a higher permission that implies CONTROL permission.
Grantees of CONTROL permission on a database, such as members of the db_owner fixed database role, can deny any permission on any securable in the database.
The following example denies CONTROL
permission on the AdventureWorks2012 user Wanida
to user RolandX
.
USE AdventureWorks2012;
DENY CONTROL ON USER::Wanida TO RolandX;
GO
The following example denies VIEW DEFINITION
permission on the AdventureWorks2012 role SammamishParking
to database user JinghaoLiu
. The CASCADE
option is specified because user JinghaoLiu
was granted VIEW DEFINITION permission WITH GRANT OPTION.
USE AdventureWorks2012;
DENY VIEW DEFINITION ON ROLE::SammamishParking
TO JinghaoLiu CASCADE;
GO
The following example denies IMPERSONATE
permission on user HamithaL
to the AdventureWorks2012 application role AccountsPayable17
.
Applies to: SQL Server 2008 through SQL Server 2008 SQL Server 2017 SQL Server 2008 SQL Server 2017 SQL Database
USE AdventureWorks2012;
DENY IMPERSONATE ON USER::HamithaL TO AccountsPayable17;
GO
GRANT Database Principal Permissions (Transact-SQL)
REVOKE Database Principal Permissions (Transact-SQL)
sys.database_principals (Transact-SQL)
sys.database_permissions (Transact-SQL)
CREATE USER (Transact-SQL)
CREATE APPLICATION ROLE (Transact-SQL)
CREATE ROLE (Transact-SQL)
GRANT (Transact-SQL)
Permissions (Database Engine)
Principals (Database Engine)