Bird
0
0

Given this trigger:

medium📝 query result Q5 of 15
SQL - Triggers
Given this trigger:
CREATE TRIGGER trg_before_update BEFORE UPDATE ON products FOR EACH ROW BEGIN IF NEW.price < 0 THEN SET NEW.price = 0; END IF; END;

What happens if you update a product's price to -50?
AThe update will be rejected with an error
BThe price will be set to -50
CThe price will be set to 0
DThe price will remain unchanged
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the trigger condition

    If NEW.price is less than 0, the trigger sets it to 0.
  2. Step 2: Apply the condition to the update value

    Since -50 < 0, NEW.price becomes 0 before update.
  3. Final Answer:

    The price will be set to 0 -> Option C
  4. Quick Check:

    BEFORE UPDATE can enforce value constraints [OK]
Quick Trick: BEFORE UPDATE triggers can correct invalid values before saving [OK]
Common Mistakes:
  • Assuming negative price is saved
  • Expecting an error instead of correction
  • Thinking price stays unchanged

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes