Step 15
6 min read

GRANT and REVOKE

Learn how to give and remove permissions - control who can do what.

What are GRANT and REVOKE?

Common Permissions
PermissionWhat User Can DoExample
SELECTRead dataView customer list
INSERTAdd new dataCreate new order
UPDATEModify dataChange price
DELETERemove dataDelete old records
ALLEverythingFull control
5 rows

GRANT gives permissions to users. REVOKE takes away permissions.

Simple analogy: Like giving someone the key to your house (GRANT) or taking it back (REVOKE).

GRANT - Give Permission

Common Permissions
PermissionWhat User Can DoExample
SELECTRead dataView customer list
INSERTAdd new dataCreate new order
UPDATEModify dataChange price
DELETERemove dataDelete old records
ALLEverythingFull control
5 rows

Example 1: Allow Someone to Read Data

GRANT SELECT ON students TO john;

Now user "john" can read the students table.

Example 2: Allow Insert and Update

GRANT INSERT, UPDATE ON products TO mary;

User "mary" can add and modify products.

Example 3: Give All Permissions

GRANT ALL ON orders TO admin_user;

Admin can do everything with orders table.

REVOKE - Remove Permission

Common Permissions
PermissionWhat User Can DoExample
SELECTRead dataView customer list
INSERTAdd new dataCreate new order
UPDATEModify dataChange price
DELETERemove dataDelete old records
ALLEverythingFull control
5 rows

Example 1: Remove Read Permission

REVOKE SELECT ON students FROM john;

User "john" can no longer read students table.

Example 2: Remove All Permissions

REVOKE ALL ON products FROM mary;

User "mary" loses all access to products.

Common Permissions

Common Permissions
PermissionWhat User Can DoExample
SELECTRead dataView customer list
INSERTAdd new dataCreate new order
UPDATEModify dataChange price
DELETERemove dataDelete old records
ALLEverythingFull control
5 rows

SELECT: Can read data INSERT: Can add new data UPDATE: Can modify data DELETE: Can remove data ALL: Can do everything

Real Example

Common Permissions
PermissionWhat User Can DoExample
SELECTRead dataView customer list
INSERTAdd new dataCreate new order
UPDATEModify dataChange price
DELETERemove dataDelete old records
ALLEverythingFull control
5 rows
-- Give sales team read-only access GRANT SELECT ON customers TO sales_team; GRANT SELECT ON orders TO sales_team; -- Give manager full access GRANT ALL ON customers TO manager; GRANT ALL ON orders TO manager;

Summary

Common Permissions
PermissionWhat User Can DoExample
SELECTRead dataView customer list
INSERTAdd new dataCreate new order
UPDATEModify dataChange price
DELETERemove dataDelete old records
ALLEverythingFull control
5 rows

GRANT = Give permissions REVOKE = Take away permissions Controls who can read/write data

Finished this topic?

Mark it complete to track your progress and maintain your streak!

SkillsetMaster - AI, Web Development & Data Analytics Courses