SQL DCL
DCL (Data Control Language) is used to grant or revoke permissions for database users.
DCL (Data Control Language) is used to control access and permissions for database users.
It determines who can access the database and what actions they can perform.
Main DCL Commands:
GRANT - Gives permission to a user. The GRANT command gives users permission to perform actions such as SELECT, INSERT, UPDATE, or DELETE.
REVOKE - Removes permission from a user. The REVOKE command removes permissions previously granted.
Syntax: GRANT Command
GRANT permission ON table_name TO user_name;
Example: Give a user permission to read data from Orders table.
GRANT SELECT ON Orders TO User1; Now User1 can view data from the Orders table.
Multiple Permissions Example
GRANT SELECT, INSERT ON Orders TO User1; User1 can now: Read data Insert new records
Syntax: REVOKE Command
REVOKE permission ON table_name FROM user_name;
Example: Remove SELECT permission from User1.
REVOKE SELECT ON Orders FROM User1; Now User1 cannot view data in the Orders table.
Advantages of DCL:
✔ Improves database security
✔ Controls user access
✔ Protects sensitive data