DENY Database Principal Permissions (Transact-SQL)
Denies permissions granted on a database user, database role, or application role.
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
Database User Permissions
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 |
Database Role Permissions
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 |
Application Role Permissions
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 |
A. Denying CONTROL permission on a user to another user
The following example denies CONTROL permission on the AdventureWorks user Wanida to user RolandX.
USE AdventureWorks; DENY CONTROL ON USER::Wanida TO RolandX; GO
B. Denying VIEW DEFINITION permission on a role to a user to which it was granted with GRANT OPTION
The following example denies VIEW DEFINITION permission on the AdventureWorks role SammamishParking to database user JinghaoLiu. The CASCADE option is specified because user JinghaoLiu was granted VIEW DEFINITION permission WITH GRANT OPTION.
USE AdventureWorks;
DENY VIEW DEFINITION ON ROLE::SammamishParking
TO JinghaoLiu CASCADE;
GO
C. Denying IMPERSONATE permission on a user to an application role
The following example denies IMPERSONATE permission on user HamithaL to the AdventureWorks application role AccountsPayable17.
USE AdventureWorks; DENY IMPERSONATE ON USER::HamithaL TO AccountsPayable17; GO
