Bird
0
0

Identify the error in this trigger definition for audit logging: CREATE TRIGGER audit_insert AFTER INSERT ON products BEGIN INSERT INTO audit_log(product_id, action) VALUES (NEW.id, 'inserted'); END;

medium📝 Troubleshoot Q6 of 15
SQL - Triggers
Identify the error in this trigger definition for audit logging: CREATE TRIGGER audit_insert AFTER INSERT ON products BEGIN INSERT INTO audit_log(product_id, action) VALUES (NEW.id, 'inserted'); END;
AIncorrect trigger timing; should be BEFORE INSERT
BMissing FOR EACH ROW clause after table name
CUsing NEW.id instead of OLD.id in AFTER INSERT trigger
DTrigger body cannot contain INSERT statements
Step-by-Step Solution
Solution:
  1. Step 1: Check trigger syntax requirements

    FOR EACH ROW is required to specify the trigger runs for each affected row.
  2. Step 2: Verify usage of NEW and timing

    NEW.id is correct for AFTER INSERT; timing is correct; INSERT statements are allowed.
  3. Final Answer:

    Missing FOR EACH ROW clause after table name -> Option B
  4. Quick Check:

    FOR EACH ROW missing in trigger syntax = Missing FOR EACH ROW clause after table name [OK]
Quick Trick: Always include FOR EACH ROW in row-level triggers [OK]
Common Mistakes:
  • Omitting FOR EACH ROW clause
  • Confusing NEW and OLD usage
  • Thinking trigger body cannot insert data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes