Bird
0
0

Given this trigger code:

medium📝 query result Q13 of 15
SQL - Triggers
Given this trigger code:
CREATE TRIGGER trg_log AFTER INSERT ON employees FOR EACH ROW BEGIN INSERT INTO log_table VALUES (NEW.id, NEW.name); END;

What happens when a new employee row is inserted?
AA new row is added to log_table with the inserted employee's id and name
BThe employees table is deleted
CThe trigger causes a syntax error
DNothing happens because NEW is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Understand the trigger action

    The trigger runs AFTER a new row is inserted into employees. It inserts a row into log_table using NEW.id and NEW.name.
  2. Step 2: Confirm NEW usage

    NEW refers to the newly inserted row's values, so the insert into log_table uses correct values.
  3. Final Answer:

    A new row is added to log_table with the inserted employee's id and name -> Option A
  4. Quick Check:

    NEW accesses inserted row data [OK]
Quick Trick: NEW accesses inserted row values inside INSERT triggers [OK]
Common Mistakes:
  • Thinking NEW is invalid outside triggers
  • Assuming trigger deletes data
  • Confusing AFTER and BEFORE timing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes