🔐 DCL (Data Control Language) in SQL
Last Updated: January 2026
DCL (Data Control Language) is a category of SQL commands used to control access and permissions in a database.
👉 DCL decides who can do what in the database.
In real-world databases:
- Multiple users exist
- Not everyone should access all data
- Permissions must be controlled
DCL helps to:
- Grant permissions
- Remove permissions
- Protect sensitive data
Hinglish Tip 🗣: Database me rights aur permissions control karna ho — kaun read kare, kaun write kare — tab DCL use hota hai.
CREATE USER
The CREATE USER command is used to create a new user in a database.
CREATE USER user_name@host_name IDENTIFIED BY 'password';
- host_name: The name of the host that the user is allowed to connect from,it can be:
- localhost (127.0.0.1)
- IP address (244.178.44.111)
- Subdomain (%.example.com )
- domain name (example.com)
- % (all hosts)
- user_name: The name of the user to be created
- password: The password for the user
Hinglish Tip 🗣: Jab database me new user banane ho, tab CREATE USER command use hota hai.
Example:
CREATE USER 'admin'@'%' IDENTIFIED BY 'password';
VIEW USERS
The VIEW USERS command is used to view all users in a database.
SELECT * FROM mysql.user;
DROP USER
The DROP USER command is used to remove a user from a database.
DROP USER user_name@host_name;
Change User Password
The SET PASSWORD command is used to change the password of a user in a database.
-- Only Work if user is already login
SET PASSWORD = "new_password";
-- OR
SET PASSWORD FOR user_name@host_name = PASSWORD('new_password');
-- OR
ALTER USER user_name@host_name IDENTIFIED BY 'new_password';
🧩 DCL Commands
We will cover each command separately in upcoming tutorials.
GRANT
- Gives permissions to users
- Controls what operations are allowed
GRANT SELECT ON table_name TO user;
REVOKE
- Removes previously granted permissions
- Restricts access
REVOKE SELECT ON table_name FROM user;
🔑 Common Permissions in DCL
- SELECT
- INSERT
- UPDATE
- DELETE
- ALL
⚠️ Important Characteristics of DCL
- Affects database security
- Used mostly by DB admins
- Permissions apply at database or table level
- Changes are usually auto-committed