What are GRANT and REVOKE?
Permission Types
| Permission | Allows User To |
|---|---|
| SELECT | Read data |
| INSERT | Add new rows |
| UPDATE | Modify existing rows |
| DELETE | Remove rows |
| ALL | Everything above |
5 rows
GRANT gives permissions to users. REVOKE takes them away.
Think of it like: Giving someone a key to your house (GRANT) or taking it back (REVOKE).
GRANT Syntax
Permission Types
| Permission | Allows User To |
|---|---|
| SELECT | Read data |
| INSERT | Add new rows |
| UPDATE | Modify existing rows |
| DELETE | Remove rows |
| ALL | Everything above |
5 rows
GRANT permission ON table_name TO user_name;Examples:
-- Allow reading
GRANT SELECT ON students TO john;
-- Allow adding and editing
GRANT INSERT, UPDATE ON products TO mary;
-- Allow everything
GRANT ALL ON orders TO admin_user;REVOKE Syntax
Permission Types
| Permission | Allows User To |
|---|---|
| SELECT | Read data |
| INSERT | Add new rows |
| UPDATE | Modify existing rows |
| DELETE | Remove rows |
| ALL | Everything above |
5 rows
REVOKE permission ON table_name FROM user_name;Examples:
-- Remove read access
REVOKE SELECT ON students FROM john;
-- Remove all access
REVOKE ALL ON products FROM mary;Real-World Example
Permission Types
| Permission | Allows User To |
|---|---|
| SELECT | Read data |
| INSERT | Add new rows |
| UPDATE | Modify existing rows |
| DELETE | Remove rows |
| ALL | Everything above |
5 rows
-- Sales team: read-only
GRANT SELECT ON customers TO sales_team;
GRANT SELECT ON orders TO sales_team;
-- Manager: full control
GRANT ALL ON customers TO manager;
GRANT ALL ON orders TO manager;
-- Remove access when employee leaves
REVOKE ALL ON customers FROM ex_employee;Summary
Permission Types
| Permission | Allows User To |
|---|---|
| SELECT | Read data |
| INSERT | Add new rows |
| UPDATE | Modify existing rows |
| DELETE | Remove rows |
| ALL | Everything above |
5 rows
- GRANT = Give permissions
- REVOKE = Remove permissions
- Control who can SELECT, INSERT, UPDATE, DELETE data