Bird
0
0

Identify the error in this trigger:

medium📝 Debug Q14 of 15
SQL - Triggers
Identify the error in this trigger:
CREATE TRIGGER trg_check BEFORE INSERT ON orders FOR EACH ROW BEGIN IF NEW.quantity < 0 THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Quantity cannot be negative'; END IF; END;
ATrigger must be AFTER INSERT, not BEFORE INSERT
BNEW cannot be used in BEFORE INSERT triggers
CSIGNAL SQLSTATE is invalid syntax
DMissing delimiter to separate statements inside BEGIN...END
Step-by-Step Solution
Solution:
  1. Step 1: Check trigger syntax for multiple statements

    Inside BEGIN...END, multiple statements need delimiters (like semicolons) or the delimiter must be changed before creating the trigger.
  2. Step 2: Confirm other parts are valid

    NEW can be used in BEFORE INSERT triggers, SIGNAL SQLSTATE is valid in many SQL dialects, and BEFORE INSERT is allowed.
  3. Final Answer:

    Missing delimiter to separate statements inside BEGIN...END -> Option D
  4. Quick Check:

    Multiple statements need delimiters [OK]
Quick Trick: Use delimiters inside BEGIN...END blocks [OK]
Common Mistakes:
  • Forgetting to change delimiter before trigger creation
  • Misusing NEW in triggers
  • Confusing BEFORE and AFTER timing rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes