Checking your session…
Module 05: SQL Command Classifications

5.4 DCL — GRANT, REVOKE

Level: 5 | Version: v1.1 | Author: Meptrasoft

Overview

DCL (Data Control Language) is commonly used for managing database permissions and access.

The two main commands are:

Command Purpose
GRANT Give permissions
REVOKE Remove permissions

GRANT → Give access
REVOKE → Take back access

DCL — GRANT and REVOKE: Control who can access what in the database
Figure 1: GRANT gives database permissions to a user or role, while REVOKE removes previously granted permissions.

GRANT

GRANT is used to give a user or role permission to perform specific operations on a database object.

Example:

SQL
GRANT SELECT, INSERT
ON employees
TO hr_user;

This gives hr_user permission to:

  • Read data using SELECT
  • Add data using INSERT

The exact syntax and available privileges can vary between database systems.

GRANT → Give permission


REVOKE

REVOKE is used to remove a previously granted permission.

Example:

SQL
REVOKE INSERT
ON employees
FROM hr_user;

After this, hr_user no longer has the INSERT permission from that grant, but may still have SELECT permission.

TEXT
Before:
SELECT ✓
INSERT ✓

After REVOKE:
SELECT ✓
INSERT ✗

REVOKE → Remove permission


Common Permissions

Database systems can provide different privileges depending on the product.

Common examples include:

TEXT
SELECT  → Read data
INSERT  → Add data
UPDATE  → Change data
DELETE  → Remove data

For example:

SQL
GRANT SELECT ON employees TO hr_user;

allows the role/user to read from employees, subject to the database's permission model.


Users and Roles

Permissions are commonly assigned to users or roles.

A role is a named collection of permissions that can be assigned to users.

For example:

TEXT
HR Role
   ↓
SELECT
INSERT
UPDATE
   ↓
HR Users

Using roles can make permission management easier when many users need similar access.


GRANT vs REVOKE

Command Action Example
GRANT Give permission GRANT SELECT ...
REVOKE Remove permission REVOKE SELECT ...

Easy Memory Trick

TEXT
GRANT  → GIVE
REVOKE → REMOVE

Why DCL Matters

Not every user should have unrestricted access to every database object.

For example:

TEXT
Student
→ View permitted student information

Teacher
→ View and update authorized academic data

Admin
→ Manage broader database access

Using permissions and roles helps follow the principle of least privilege:

Give users only the access they need to perform their job.


Common Beginner Mistakes

✗ Mistake ✓ Correct Understanding
GRANT gives a user the entire database It grants specified privileges on specified objects
REVOKE deletes the user It removes a specified privilege
DCL changes table data DCL manages access and permissions
SELECT means the user can modify data SELECT normally provides read access
Every database uses exactly the same privilege syntax Permission syntax and behavior vary by database product
Permissions should be given to everyone Access should follow appropriate security requirements and least privilege

Placement Quick Points

TEXT
DCL
→ ACCESS CONTROL

GRANT
→ GIVE PERMISSION

REVOKE
→ REMOVE PERMISSION

SELECT
→ READ

INSERT
→ ADD

UPDATE
→ MODIFY

DELETE
→ REMOVE
  • DCL is commonly used to manage database access and permissions.
  • GRANT gives privileges to users or roles.
  • REVOKE removes previously granted privileges.
  • Permissions can be assigned to users or roles.
  • Common privileges include SELECT, INSERT, UPDATE, and DELETE.
  • Permission syntax and behavior can vary between database systems.
  • Least privilege helps reduce unnecessary access.

Interview Questions

What is DCL?

DCL stands for Data Control Language and is commonly used to manage database permissions and access.

What is GRANT?

GRANT gives a user or role permission to perform specified operations on database objects.

What is REVOKE?

REVOKE removes previously granted permissions.

What is the difference between GRANT and REVOKE?
TEXT
GRANT  → Give permission
REVOKE → Remove permission
What is a database role?

A role is a named collection of permissions that can be assigned to users, making access management easier.

Why are database permissions important?

They help prevent unauthorized users from viewing or modifying data and allow access to be controlled according to user responsibilities.


Practice & Hands-On Exercises

DCL commands require appropriate database users/roles and permissions, so they may not be executable in a shared learning environment.

  1. Explain what this command does:
SQL
GRANT SELECT, INSERT
ON employees
TO hr_user;
  1. Explain what this command does:
SQL
REVOKE INSERT
ON employees
FROM hr_user;
  1. After the REVOKE, which permission does hr_user still have?
  2. Explain why roles are useful when many users need the same permissions.
  3. Give one example of a user who should have read-only access.

💡 Tip: Test your queries using the in-browser interactive runner above.


Key Takeaway

TEXT
DCL
 ↓
ACCESS CONTROL

GRANT
 ↓
GIVE PERMISSION

REVOKE
 ↓
REMOVE PERMISSION

DCL controls access to database objects: GRANT gives permissions, while REVOKE removes permissions.

End of DCL — GRANT, REVOKE