Bird
0
0

You wrote this trigger to log deletions:

medium📝 Troubleshoot Q14 of 15
SQL - Triggers
You wrote this trigger to log deletions:
CREATE TRIGGER log_delete AFTER DELETE ON orders FOR EACH ROW BEGIN INSERT INTO audit_orders (order_id, deleted_at) VALUES (NEW.id, NOW()); END;

Why does this trigger cause an error?
AMissing FOR EACH STATEMENT clause
BUsing NEW keyword in a DELETE trigger causes an error
CNOW() function is not allowed in triggers
DTrigger must be BEFORE DELETE, not AFTER DELETE
Step-by-Step Solution
Solution:
  1. Step 1: Recall OLD and NEW usage in triggers

    In DELETE triggers, only OLD is available because the row is removed; NEW does not exist.
  2. Step 2: Identify the error cause

    The trigger uses NEW.id in a DELETE trigger, which causes an error because NEW is undefined.
  3. Final Answer:

    Using NEW keyword in a DELETE trigger causes an error -> Option B
  4. Quick Check:

    DELETE triggers use OLD, not NEW [OK]
Quick Trick: Use OLD in DELETE triggers, NEW causes errors [OK]
Common Mistakes:
  • Using NEW instead of OLD in DELETE triggers
  • Confusing FOR EACH ROW and FOR EACH STATEMENT
  • Thinking NOW() is disallowed in triggers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes