0% found this document useful (0 votes)
92 views

DCL in SQL

DCL commands in SQL are used to control access privileges for database users. The main DCL commands are GRANT, which gives privileges to users, and REVOKE, which removes privileges. Examples show GRANT giving users SELECT permission on tables and REVOKE removing DELETE permission. Additional DCL commands include WITH GRANT OPTION, DENY, commands for managing roles, ALTER USER, and granting system-level privileges.

Uploaded by

MAHMOOD HUSSAIN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

DCL in SQL

DCL commands in SQL are used to control access privileges for database users. The main DCL commands are GRANT, which gives privileges to users, and REVOKE, which removes privileges. Examples show GRANT giving users SELECT permission on tables and REVOKE removing DELETE permission. Additional DCL commands include WITH GRANT OPTION, DENY, commands for managing roles, ALTER USER, and granting system-level privileges.

Uploaded by

MAHMOOD HUSSAIN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Data Control Language (DCL) in SQL is a subset of SQL commands that are used to control

access to data within a database.


DCL commands primarily involve granting or revoking permissions to database users.
Here are some examples of DCL commands in SQL:

GRANT: This command is used to give specific privileges to a user or role.

1. GRANT SELECT, INSERT ON employees TO user1;


This grants the user user1 the privilege to select and insert data into the employees table.

REVOKE: This command is used to take away previously granted privileges from a user
or role.

2. REVOKE DELETE ON customers FROM user2;


This revokes the privilege to delete data from the customers table from user2.

3. WITH GRANT OPTION: When granting privileges, you can include the WITH GRANT
OPTION clause to allow the recipient to further grant the same privilege to others.

4. GRANT SELECT ON products TO user3 WITH GRANT OPTION;


This grants user3 the right to select data from the products table and also allows them to grant the
SELECT privilege to other users.

DENY (Not supported in all databases): Some databases support a DENY command,
which explicitly denies a user or role a specific privilege.
However, not all database management systems support this command.

5. DENY UPDATE ON orders TO user4;


This denies the UPDATE privilege on the orders table to user4.
ROLE MANAGEMENT: DCL commands can also be used to manage roles.
Roles are a way to group users and assign privileges to the role, making it easier to manage
permissions.

6. CREATE ROLE finance_team;

7. GRANT SELECT ON salary_data TO finance_team;

This example creates a role called finance_team and grants it the SELECT privilege on the
salary_data table.

ALTER USER: You can use the ALTER USER command to modify the privileges of a
user.

8. ALTER USER user5 NOLOGIN;


This command can be used to prevent user5 from logging in.

SYSTEM GRANTS: DCL commands can also control system-level privileges, such as
creating databases or altering the schema.

9. GRANT CREATE DATABASE TO admin_user;


This grants the privilege to create databases to admin_user.

You might also like