TechNet
Export (0) Print
Expand All

DENY (Transact-SQL)

 

Updated: June 10, 2016

THIS TOPIC APPLIES TO: yesSQL Server (starting with 2008)yesAzure SQL DatabaseyesAzure SQL Data Warehouse yesParallel Data Warehouse

Denies a permission to a principal. Prevents that principal from inheriting the permission through its group or role memberships.

Topic link icon Transact-SQL Syntax Conventions

  
Simplified syntax for DENY  
DENY { ALL [ PRIVILEGES ] }  
      | permission [ ( column [ ,...n ] ) ] [ ,...n ]  
      [ ON [ class :: ] securable ] TO principal [ ,...n ]   
      [ CASCADE] [ AS principal ]  

-- Azure SQL Data Warehouse and Parallel Data Warehouse  
DENY   
    <permission> [ ,...n ]  
    [ ON [ <class_type> :: ] securable ]   
    TO principal [ ,...n ]  
    [ CASCADE ]  
[;]  
  
<permission> ::=  
{ see the tables below }  
  
<class_type> ::=  
{  
      LOGIN  
    | DATABASE  
    | OBJECT  
    | ROLE  
    | SCHEMA  
    | USER  
}  

ALL
This option does not deny all possible permissions. Denying ALL is equivalent to denying the following permissions.

  • If the securable is a database, ALL means BACKUP DATABASE, BACKUP LOG, CREATE DATABASE, CREATE DEFAULT, CREATE FUNCTION, CREATE PROCEDURE, CREATE RULE, CREATE TABLE, and CREATE VIEW.

  • If the securable is a scalar function, ALL means EXECUTE and REFERENCES.

  • If the securable is a table-valued function, ALL means DELETE, INSERT, REFERENCES, SELECT, and UPDATE.

  • If the securable is a stored procedure, ALL means EXECUTE.

  • If the securable is a table, ALL means DELETE, INSERT, REFERENCES, SELECT, and UPDATE.

  • If the securable is a view, ALL means DELETE, INSERT, REFERENCES, SELECT, and UPDATE.

System_CAPS_ICON_note.jpg Note


The DENY ALL syntax is deprecated. This feature will 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. Deny specific permissions instead.

PRIVILEGES
Included for ISO compliance. Does not change the behavior of ALL.

permission
Is the name of a permission. The valid mappings of permissions to securables are described in the sub-topics listed below.

column
Specifies the name of a column in a table on which permissions are being denied. The parentheses () are required.

class
Specifies the class of the securable on which the permission is being denied. The scope qualifier :: is required.

securable
Specifies the securable on which the permission is being denied.

TO principal
Is the name of a principal. The principals to which permissions on a securable can be denied vary, depending on the securable. See the securable-specific topics listed below for valid combinations.

CASCADE
Indicates that the permission is denied to the specified principal and to all other principals to which the principal granted the permission. Required when the principal has the permission with GRANT OPTION.

AS principal
Use the AS principal clause to indicate that the principal recorded as the denier of the permission should be a principal other than the person executing the statement. For example, presume that user Mary is principal_id 12 and user Raul is principal 15. Mary executes DENY SELECT ON OBJECT::X TO Steven WITH GRANT OPTION AS Raul; Now the sys.database_permissions table will indicate that the grantor_prinicpal_id of the deny statement was 15 (Raul) even though the statement was actually executed by user 13 (Mary).

The use of AS in this statement does not imply the ability to impersonate another user.

The full syntax of the DENY statement is complex. The syntax diagram above was simplified to draw attention to its structure. Complete syntax for denying permissions on specific securables is described in the topics listed below.

DENY will fail if CASCADE is not specified when denying a permission to a principal that was granted that permission with GRANT OPTION specified.

The sp_helprotect system stored procedure reports permissions on a database-level securable.

System_CAPS_ICON_caution.jpg Caution


A table-level DENY does not take precedence over a column-level GRANT. This inconsistency in the permissions hierarchy has been preserved for the sake of backward compatibility. It will be removed in a future release.

System_CAPS_ICON_caution.jpg Caution


Denying CONTROL permission on a database implicitly denies CONNECT permission on the database. A principal that is denied CONTROL permission on a database will not be able to connect to that database.

System_CAPS_ICON_caution.jpg Caution


Denying CONTROL SERVER permission implicitly denies CONNECT SQL permission on the server. A principal that is denied CONTROL SERVER permission on a server will not be able to connect to that server.

The caller (or the principal specified with the AS option) must have either CONTROL permission on the securable, or a higher permission that implies CONTROL permission on the securable. If using the AS option, the specified principal must own the securable on which a permission is being denied.

Grantees of CONTROL SERVER permission, such as members of the sysadmin fixed server role, can deny any permission on any securable in the server. Grantees of CONTROL permission on the database, such as members of the db_owner fixed database role, can deny any permission on any securable in the database. Grantees of CONTROL permission on a schema can deny any permission on any object in the schema. If the AS clause is used, the specified principal must own the securable on which permissions are being denied.

The following table lists the securables and the topics that describe the securable-specific syntax.

Application RoleDENY Database Principal Permissions (Transact-SQL)
AssemblyDENY Assembly Permissions (Transact-SQL)
Asymmetric KeyDENY Asymmetric Key Permissions (Transact-SQL)
Availability GroupDENY Availability Group Permissions (Transact-SQL)
CertificateDENY Certificate Permissions (Transact-SQL)
ContractDENY Service Broker Permissions (Transact-SQL)
DatabaseDENY Database Permissions (Transact-SQL)
EndpointDENY Endpoint Permissions (Transact-SQL)
Full-Text CatalogDENY Full-Text Permissions (Transact-SQL)
Full-Text StoplistDENY Full-Text Permissions (Transact-SQL)
FunctionDENY Object Permissions (Transact-SQL)
LoginDENY Server Principal Permissions (Transact-SQL)
Message TypeDENY Service Broker Permissions (Transact-SQL)
ObjectDENY Object Permissions (Transact-SQL)
QueueDENY Object Permissions (Transact-SQL)
Remote Service BindingDENY Service Broker Permissions (Transact-SQL)
RoleDENY Database Principal Permissions (Transact-SQL)
RouteDENY Service Broker Permissions (Transact-SQL)
SchemaDENY Schema Permissions (Transact-SQL)
Search Property ListDENY Search Property List Permissions (Transact-SQL)
ServerDENY Server Permissions (Transact-SQL)
ServiceDENY Service Broker Permissions (Transact-SQL)
Stored ProcedureDENY Object Permissions (Transact-SQL)
Symmetric KeyDENY Symmetric Key Permissions (Transact-SQL)
SynonymDENY Object Permissions (Transact-SQL)
System ObjectsDENY System Object Permissions (Transact-SQL)
TableDENY Object Permissions (Transact-SQL)
TypeDENY Type Permissions (Transact-SQL)
UserDENY Database Principal Permissions (Transact-SQL)
ViewDENY Object Permissions (Transact-SQL)
XML Schema CollectionDENY XML Schema Collection Permissions (Transact-SQL)

REVOKE (Transact-SQL)
sp_addlogin (Transact-SQL)
sp_adduser (Transact-SQL)
sp_changedbowner (Transact-SQL)
sp_dropuser (Transact-SQL)
sp_helprotect (Transact-SQL)
sp_helpuser (Transact-SQL)

Community Additions

ADD
Show:
© 2016 Microsoft