DCL

Also known as: Data control language

On this page 7

DCL (data control language) is the subset of SQL statements that controls who may access which database objects and how, chiefly through the GRANT and REVOKE commands. Where DDL defines structures and DML reads and changes rows, DCL governs authorization: it records privileges in the system catalog so that the database engine can check every later statement against them.

In relational databases, DCL is the language-level expression of the principle of least privilege. A well-designed permission scheme limits the damage of a compromised account, separates duties between developers, operators and applications, and gives auditors a clear, queryable record of access rights.

How DCL statements work in SQL

A DCL statement modifies privilege metadata, not user data. When an administrator runs GRANT SELECT ON orders TO reporting, the engine writes an entry into its access control list for the orders table. Every subsequent query from a member of reporting passes through an authorization check that consults these entries before the optimizer even builds a plan.

The model has three parts: a grantee (a user, a role or the special group PUBLIC), a privilege (an action such as SELECT or EXECUTE) and a securable object (a database, schema, table, view, column, sequence or routine). The SQL standard defines the core syntax, and every major vendor extends it with its own privileges and object types.

The following table lists the core DCL statements and their effect.

StatementPurposeTypical form
GRANTGives a privilege or role to a granteeGRANT SELECT ON sales TO analyst
REVOKERemoves a previously granted privilegeREVOKE UPDATE ON sales FROM analyst
DENYExplicitly blocks a privilege (SQL Server only)DENY DELETE ON sales TO intern
GRANT roleAdds a user to a roleGRANT analyst TO maria
WITH GRANT OPTIONLets the grantee pass the privilege onGRANT SELECT ON sales TO lead WITH GRANT OPTION
Core DCL statements

Privilege types and object scope

Privileges fall into object privileges, which apply to a named object, and system privileges, which allow actions across the instance, such as creating databases or managing users. Object privileges can be scoped narrowly; most engines support column-level grants, so a support role may read customer names without seeing payment details.

The table below summarizes common object privileges and the statements they authorize.

PrivilegeApplies toAuthorizes
SELECTTables, views, columns, sequencesReading rows or values
INSERTTables, views, columnsAdding new rows
UPDATETables, views, columnsChanging existing values
DELETETables, viewsRemoving rows
EXECUTEFunctions, proceduresRunning stored routines
REFERENCESTables, columnsCreating foreign keys that point to the object
USAGESchemas, sequences, typesUsing the object without reading its data
Common object privileges

Privileges are cumulative across roles: a user holds the union of everything granted directly and through every role. SQL Server adds DENY, which overrides any grant, while PostgreSQL, MySQL and Oracle have no explicit deny and rely only on the absence of a grant.

DCL compared with DDL, DML and TCL

SQL is traditionally divided into sublanguages by purpose, and DCL is the one concerned with security rather than structure or content. The categories are conventions, not separate parsers, and some vendors classify statements differently.

SublanguageConcernExample statementsTransactional behavior
DDLSchema structureCREATE TABLE, ALTER TABLE, DROPImplicit commit in Oracle and MySQL
DMLRow dataINSERT, UPDATE, DELETE, SELECTFully transactional
DCLAccess rightsGRANT, REVOKE, DENYVaries by engine
TCLTransaction boundariesCOMMIT, ROLLBACK, SAVEPOINTControls the transaction itself
SQL sublanguages compared

The transactional row matters in practice. In PostgreSQL and SQL Server, a GRANT inside a transaction can be rolled back, whereas Oracle and MySQL commit DCL implicitly, so a failed deployment script may leave permissions half applied.

Designing permissions with roles

Mature systems grant privileges to roles, not individual users, an approach known as role-based access control (RBAC). Users then receive roles that match their job function. This keeps the privilege catalog small, makes onboarding and offboarding a single statement, and lets auditors review a handful of roles instead of hundreds of personal grants.

The decision table below shows typical role patterns for an application database.

RoleGranted privilegesReason
app_readwriteSELECT, INSERT, UPDATE, DELETE on application schemaService account needs data access only
app_readonlySELECT on application schemaReporting and analytics without write risk
migration_ownerObject ownership and DDL rightsSchema changes run from deployment pipeline
dba_adminSystem privileges, role managementSmall team responsible for the instance
Typical role design for an application database

A key detail is default privileges for objects created later. PostgreSQL uses ALTER DEFAULT PRIVILEGES so that new tables automatically become readable by app_readonly; without it, every new table silently lacks the expected grants until someone notices failing queries.

Limitations and common mistakes

DCL controls access at the object and column level, but it does not filter individual rows. Row-level security requires separate features, such as PostgreSQL policies or Oracle Virtual Private Database, or views that embed filtering logic. Several recurring errors weaken DCL-based security:

  • Granting to PUBLIC exposes objects to every current and future account.
  • Using WITH GRANT OPTION carelessly lets privileges spread beyond the administrator’s view.
  • Running applications as the object owner or superuser bypasses most privilege checks entirely.
  • Assuming REVOKE always succeeds: a privilege held through a role or another grantor remains in effect after a direct revoke.
  • Forgetting cascading revokes: REVOKE ... CASCADE also removes privileges the grantee passed on, which may break other users.

Permission state should be managed as code, reviewed and versioned like schema migrations, and periodically compared with the live catalog through views such as information_schema.table_privileges to detect privilege drift.

A plain-language summary

DCL is the part of SQL that hands out and takes back keys. A database holds many rooms, such as tables of customers, orders and salaries. DCL commands decide who receives a key to which room and whether that key only opens the door to look or also allows moving things around.

GRANT gives a key, and REVOKE takes it away. Instead of handing keys to each person, administrators usually give them to groups called roles, so a new employee simply joins the right group. The key takeaway is simple: everyone should get only the keys their work requires.

An example from practice

A mid-sized online retailer runs its order system on PostgreSQL. Originally, the web application, the reporting tool and three developers all connected with the same owner account. After a reporting query accidentally ran an UPDATE that overwrote 40,000 shipping addresses, the team redesigned access with DCL.

They created four purpose-specific roles: app_readwrite for the web service, app_readonly for reporting, migration_owner for the deployment pipeline and dba_admin for two administrators. Column-level grants hid the card_token column from the reporting role, and ALTER DEFAULT PRIVILEGES ensured that new tables were readable by reporting automatically.

The outcome was measurable: the reporting tool could no longer modify data, developers lost direct production write access, and a quarterly audit now reviews four roles instead of eleven personal accounts. The entire permission set lives in a versioned migration file that is applied on every environment.