advancedTop 30 Scenario-Based Questions

You need to implement full audit logging for all DML on the orders table in PostgreSQL. How?

Trigger-based audit: CREATE TABLE orders_audit (audit_id BIGSERIAL, operation CHAR(1), changed_by TEXT, changed_at TIMESTAMP, old_data JSONB, new_data JSONB); CREATE OR REPLACE FUNCTION log_orders_audit() RETURNS TRIGGER AS [func_body] CREATE TRIGGER orders_audit_trigger AFTER INSERT OR UPDATE OR DELETE ON orders FOR EACH ROW EXECUTE FUNCTION log_orders_audit(). In trigger body: operation = TG_OP[

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to Write a query to find products that have never been ordered.← Back to all SQL questions