GRANT, REVOKE & Roles in SQL
Least privilege per role — tables, columns, actions
DCL gates access: GRANT SELECT/INSERT/UPDATE/DELETE ON tables (or columns) TO roles; REVOKE removes. Roles collect privileges; users inherit via membership. Least privilege contains injection blast radius and buggy jobs. Views + RLS refine to row/column granularity where table grants are too coarse.
Grant minimal verbs
SELECT/INSERT/UPDATE scoped per table/column to each role.
Revoke danger
DELETE/DDL removed from support/analyst paths by default.
Roles carry grants
Users inherit via membership — auditable, revocable in one place.
Refine past tables
Views + RLS for row/column granularity table grants cannot express.
1GRANT SELECT ON employees TO analyst;2REVOKE DELETE ON employees FROM analyst;
| role | grants |
|---|---|
| analyst | SELECT only |
| app_writer | INSERT/UPDATE scoped |
| admin | DDL + grants |
Analyst reads but cannot delete or alter. App writer mutates its tables only. Admin holds DDL separately — breach of one role cannot drop schemas.
Analyst column scope
Reads names, never salaries or deletes.
1GRANT SELECT (id, name) ON employees TO analyst;2REVOKE DELETE ON employees FROM analyst;
| role | grants |
|---|---|
| analyst | SELECT (id,name) only |
| support | no DELETE/DDL |
Service writer role
App mutates its tables, nothing else.
1CREATE ROLE app_writer;2GRANT SELECT, INSERT, UPDATE ON orders TO app_writer;3GRANT app_writer TO app_svc;
| role | scope |
|---|---|
| app_writer | orders CRUD scoped |
| membership | app_svc inherits |
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Take the queries you just visualized and see the data structures that power real databases.