Skip to the content.

SQL > Data Control Language (DCL)

Introduction

Data Control Language (DCL) is a subset of SQL that is used to control access to data in a database. It helps in defining user permissions and restricting unauthorized access.

Key DCL Commands:


GRANT

Purpose:

The GRANT command is used to give specific privileges to a user in the database.

Syntax:

GRANT privilege_name ON object_name TO user_name;

Examples:

Grant SELECT permission on a table:

GRANT SELECT ON Employees TO 'john'@'localhost';

Grant multiple privileges:

GRANT SELECT, INSERT, UPDATE ON Employees TO 'admin'@'localhost';

Grant all privileges on a database:

GRANT ALL PRIVILEGES ON CompanyDB.* TO 'manager'@'localhost';

REVOKE

Purpose:

The REVOKE command is used to remove previously granted privileges from a user.

Syntax:

REVOKE privilege_name ON object_name FROM user_name;

Examples:

Revoke SELECT permission from a user:

REVOKE SELECT ON Employees FROM 'john'@'localhost';

Revoke multiple privileges:

REVOKE SELECT, INSERT ON Employees FROM 'admin'@'localhost';

Revoke all privileges from a user:

REVOKE ALL PRIVILEGES ON CompanyDB.* FROM 'manager'@'localhost';

Summary

Command Description
GRANT Provides specific privileges to users.
REVOKE Removes privileges from users.

Next Topic: Transaction Control Language (TCL) →