Bird
0
0

Why is it important to use FOR EACH ROW instead of FOR EACH STATEMENT in audit logging triggers?

hard📝 Conceptual Q10 of 15
SQL - Triggers
Why is it important to use FOR EACH ROW instead of FOR EACH STATEMENT in audit logging triggers?
AFOR EACH STATEMENT runs the trigger multiple times per row, causing duplicates
BFOR EACH ROW triggers cannot access OLD or NEW values
CFOR EACH ROW logs every individual row change, ensuring detailed audit records
DFOR EACH STATEMENT triggers are faster and preferred for audit logging
Step-by-Step Solution
Solution:
  1. Step 1: Understand difference between FOR EACH ROW and FOR EACH STATEMENT

    FOR EACH ROW runs once per affected row; FOR EACH STATEMENT runs once per SQL statement.
  2. Step 2: Identify audit logging needs

    Audit logging requires detailed info per row change, so FOR EACH ROW is necessary.
  3. Final Answer:

    FOR EACH ROW logs every individual row change, ensuring detailed audit records -> Option C
  4. Quick Check:

    Detailed audit needs FOR EACH ROW triggers = FOR EACH ROW logs every individual row change, ensuring detailed audit records [OK]
Quick Trick: Use FOR EACH ROW for detailed audit logs per row change [OK]
Common Mistakes:
  • Confusing FOR EACH STATEMENT with multiple executions
  • Thinking FOR EACH ROW cannot access OLD/NEW
  • Believing FOR EACH STATEMENT is better for audit detail

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes