intermediateAdvanced SQL — Stored Procedures, Functions, Triggers & Sequences

What's the practical difference between a BEFORE trigger and an AFTER trigger?

A BEFORE trigger runs before the write happens and its return value actually replaces the row that gets written (or NULL cancels the write entirely) — it can inspect and modify the row. An AFTER trigger runs once the write has already happened, typically for side effects like audit logging, and its return value is ignored since the write can no longer be changed.

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 Why does WHERE column = NULL never match any rows, even when the column genuinely contains NULLs?← Back to all SQL questions