DCL (Data Control Language)
Reviewed by Rikesh
on
October 06, 2024
Rating:
![DCL (Data Control Language)](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-i9qzpRtoDsW3ZDhlzEZq2OgFt1rs7menYRGRkC6OH995kxKLKuMMWnda8DKwRiyamhyphenhyphennl5u3fQ9Kug_3RfOJI8d7lCrrGXxzMcD5mph_yIoq-s-r7FSElMNI_u4Zk8hMp1DpHf6Nh4IHgrY11MHt4BC_MiB0v86Y1_PbPcap72x7LiSczYHDVinc0rOu/s72-c/What%20is%20DCL%20in%20Sql.png)
DCL (Data Control Language) in SQL is used to control access to data within the database. It includes commands that control the permissions and access rights of users. DCL mainly comprises two key commands:
GRANT: This command is used to give users access privileges or permissions on the database objects like tables, views, sequences, etc.
Syntax:
GRANT privilege_name ON object_name TO user_name;
privilege_name
: Type of privilege (e.g., SELECT, INSERT, UPDATE, DELETE, etc.).object_name
: The name of the database object (e.g., table).user_name
: The name of the user or role to whom the privilege is granted.Example:
GRANT SELECT, INSERT ON Employees TO John;
This gives the user John
permission to SELECT
and INSERT
data into the Employees
table.
REVOKE: This command is used to take back permissions granted to the user.
Syntax:
REVOKE privilege_name ON object_name FROM user_name;
privilege_name
: Type of privilege to be revoked.object_name
: The name of the database object.user_name
: The name of the user or role from whom the privilege is revoked.Example:
REVOKE SELECT, INSERT ON Employees FROM John;
This removes the SELECT
and INSERT
permissions from the user John
for the Employees
table.
No comments: