Bird
0
0

Given this AFTER UPDATE trigger:

medium📝 query result Q5 of 15
PostgreSQL - Triggers in PostgreSQL
Given this AFTER UPDATE trigger:
CREATE TRIGGER trg_after_update AFTER UPDATE ON products FOR EACH ROW EXECUTE FUNCTION log_update();

What will happen if an UPDATE statement modifies multiple rows?
AThe log_update() function runs only once after all rows update.
BThe trigger runs before the update statement.
CThe trigger will not run for multiple rows.
DThe log_update() function runs once for each updated row.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze FOR EACH ROW behavior

    FOR EACH ROW triggers execute once per affected row, even if multiple rows are updated.
  2. Step 2: Confirm timing and frequency

    Since it's an AFTER UPDATE trigger, the function runs after each row update, multiple times if multiple rows change.
  3. Final Answer:

    The log_update() function runs once for each updated row. -> Option D
  4. Quick Check:

    FOR EACH ROW triggers run per row updated [OK]
Quick Trick: FOR EACH ROW triggers run once per affected row [OK]
Common Mistakes:
  • Thinking trigger runs once per statement
  • Confusing BEFORE and AFTER timing
  • Assuming trigger skips multiple rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes