Bird
0
0

You wrote this trigger:

medium📝 Debug Q14 of 15
SQL - Triggers
You wrote this trigger:
CREATE TRIGGER trg_check BEFORE INSERT ON Users BEGIN IF NEW.age < 18 THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Age must be 18 or older'; END IF; END;

But it does not prevent inserting users younger than 18. What is the likely error?
AThe trigger does not have a proper delimiter for multiple statements
BThe SIGNAL statement syntax is incorrect
CThe trigger should be AFTER INSERT, not BEFORE
DTriggers cannot check conditions on NEW data
Step-by-Step Solution
Solution:
  1. Step 1: Analyze trigger structure with multiple statements

    The trigger has IF and SIGNAL inside BEGIN...END, which requires proper statement delimiters (like semicolons) to separate commands.
  2. Step 2: Identify missing delimiter issue

    Without delimiters, the database cannot parse the trigger body correctly, so the condition check fails.
  3. Final Answer:

    The trigger does not have a proper delimiter for multiple statements -> Option A
  4. Quick Check:

    Missing delimiters cause trigger failure = A [OK]
Quick Trick: Use delimiters for multiple statements in triggers [OK]
Common Mistakes:
  • Changing BEFORE to AFTER incorrectly
  • Assuming SIGNAL syntax is wrong without checking
  • Believing triggers can't access NEW data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes