sql / intermediate
Snippet
Restricting Data Access via Least-Privilege Grants
Database access control relies on explicitly granting minimum necessary permissions to specific database roles while restricting destructive privileges. Standard DCL statements like GRANT and REVOKE maintain overall data integrity and access security.
snippet.sql
sql
1
2
GRANT SELECT, INSERT ON TABLE audit_logs TO ROLE auditor_role;REVOKE DELETE, UPDATE ON TABLE audit_logs FROM ROLE auditor_role;
Breakdown
1
GRANT SELECT, INSERT ON TABLE audit_logs TO ROLE auditor_role;
Grants read and write insertion access on the audit_logs table to auditor_role.
2
REVOKE DELETE, UPDATE ON TABLE audit_logs FROM ROLE auditor_role;
Explicitly removes modification and deletion rights on the audit_logs table from auditor_role.