Bird
0
0

You wrote this AFTER INSERT trigger:

medium📝 Debug Q6 of 15
PostgreSQL - Triggers in PostgreSQL
You wrote this AFTER INSERT trigger:
CREATE TRIGGER trg_after_insert AFTER INSERT ON sales EXECUTE FUNCTION log_sale();

But it gives an error. What is the likely cause?
ATable name 'sales' is reserved.
BMissing FOR EACH ROW or FOR EACH STATEMENT clause.
CAFTER triggers cannot be created on INSERT.
DTrigger function name is invalid.
Step-by-Step Solution
Solution:
  1. Step 1: Check trigger syntax requirements

    PostgreSQL requires specifying FOR EACH ROW or FOR EACH STATEMENT in CREATE TRIGGER.
  2. Step 2: Identify missing clause

    The given statement lacks this clause, causing syntax error.
  3. Final Answer:

    Missing FOR EACH ROW or FOR EACH STATEMENT clause. -> Option B
  4. Quick Check:

    Trigger syntax requires FOR EACH ROW/STATEMENT [OK]
Quick Trick: Always specify FOR EACH ROW or FOR EACH STATEMENT in triggers [OK]
Common Mistakes:
  • Omitting FOR EACH ROW/STATEMENT clause
  • Assuming AFTER triggers disallowed on INSERT
  • Thinking table names cause trigger errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes