Bird
0
0

Consider this trigger:

medium📝 query result Q4 of 15
SQL - Triggers
Consider this trigger:
CREATE TRIGGER trg_before_insert BEFORE INSERT ON employees FOR EACH ROW BEGIN SET NEW.salary = NEW.salary * 1.1; END;

What will happen if you insert a row with salary = 1000?
AThe salary will remain 1000
BThe salary will be stored as 1100
CThe insert will fail with an error
DThe salary will be stored as 100
Step-by-Step Solution
Solution:
  1. Step 1: Understand the trigger logic

    The trigger multiplies the NEW.salary by 1.1 before insert.
  2. Step 2: Calculate the new salary value

    1000 * 1.1 = 1100, so the stored salary will be 1100.
  3. Final Answer:

    The salary will be stored as 1100 -> Option B
  4. Quick Check:

    BEFORE INSERT can modify NEW values [OK]
Quick Trick: BEFORE triggers can change inserted values before saving [OK]
Common Mistakes:
  • Assuming salary stays unchanged
  • Thinking trigger causes error
  • Miscomputing the multiplication

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes