Data Control Language (DCL) Commands

Perfect ๐Ÿ‘
Now DCL commands in the exact same pattern you liked:

  • Base state

  • Question

  • SQL

  • Result / Output (privilege table)

  • ✔ clear takeaways


๐Ÿ“˜ Base State (Before DCL Commands)

Users & Table

  • User: john_doe

  • Table: employees

Existing Privileges (Initially)

UserTableSELECTINSERTUPDATEDELETE
john_doeemployees❌❌❌❌

๐Ÿงพ Summary Table (DCL Questions)

No.DCL CommandQuestion
1GRANTGive SELECT & INSERT access
2REVOKERemove SELECT & INSERT access

1️⃣ GRANT

Question: Give user john_doe permission to SELECT and INSERT data from employees table.

GRANT SELECT, INSERT
ON employees
TO john_doe;

✅ Result (Privileges AFTER GRANT)

UserTableSELECTINSERTUPDATEDELETE
john_doeemployees✅✅❌❌

✔ User can read data (SELECT)
✔ User can add data (INSERT)
✔ Other actions still restricted


2️⃣ REVOKE

Question: Remove SELECT and INSERT permissions from user john_doe.

REVOKE SELECT, INSERT
ON employees
FROM john_doe;

✅ Result (Privileges AFTER REVOKE)

UserTableSELECTINSERTUPDATEDELETE
john_doeemployees❌❌❌❌

✔ Access removed
✔ User can no longer read or insert data


๐Ÿ”ฅ GRANT vs REVOKE (Exam Favorite)

FeatureGRANTREVOKE
PurposeGive permissionTake permission
AffectsUser / RoleUser / Role
Data change❌ No❌ No
Structure change❌ No❌ No
CategoryDCLDCL

๐Ÿง  One-Line Memory Trick (DCL)

CommandMeaning
GRANTAllow access
REVOKERemove access

⚠️ Exam Notes (Important)

  • DCL commands do not modify data

  • Used mainly by DBA / Admin

  • Privileges can be given on table, view, database


If you want next:

  • TCL commands (COMMIT, ROLLBACK, SAVEPOINT)

  • Complete SQL cheat-sheet (DDL + DML + DCL + TCL)

  • MCQs with privilege-based output

  • Hindi explanation for exams

Just say ๐Ÿ‘

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.