Bird
0
0

Which of the following is the correct syntax to create a simple AFTER INSERT trigger in SQL?

easy📝 Syntax Q12 of 15
SQL - Triggers
Which of the following is the correct syntax to create a simple AFTER INSERT trigger in SQL?
ACREATE TRIGGER trg AFTER INSERT employees BEGIN UPDATE stats SET count = count + 1; END;
BCREATE TRIGGER trg AFTER INSERT ON employees FOR EACH ROW BEGIN UPDATE stats SET count = count + 1; END;
CCREATE TRIGGER trg BEFORE UPDATE ON employees FOR EACH ROW UPDATE stats SET count = count + 1;
DCREATE TRIGGER trg ON employees AFTER INSERT BEGIN UPDATE stats SET count = count + 1; END;
Step-by-Step Solution
Solution:
  1. Step 1: Check trigger timing and event

    The trigger is AFTER INSERT on the employees table, so syntax must include 'AFTER INSERT ON employees'.
  2. Step 2: Verify trigger body structure

    The trigger body must be enclosed in BEGIN ... END; and include FOR EACH ROW for row-level triggers.
  3. Final Answer:

    CREATE TRIGGER trg AFTER INSERT ON employees FOR EACH ROW BEGIN UPDATE stats SET count = count + 1; END; -> Option B
  4. Quick Check:

    Correct syntax includes timing, event, table, and body [OK]
Quick Trick: Look for 'AFTER INSERT ON table FOR EACH ROW' syntax [OK]
Common Mistakes:
  • Omitting 'ON' keyword before table name
  • Missing 'FOR EACH ROW' for row-level triggers
  • Incorrect order of keywords

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes