Bird
0
0

You want to log every change to the customers table without slowing down transactions. Which approach best improves trigger performance?

hard📝 optimization Q15 of 15
SQL - Triggers
You want to log every change to the customers table without slowing down transactions. Which approach best improves trigger performance?
AUse triggers to update multiple related tables during each change
BUse a BEFORE UPDATE trigger that performs complex calculations before logging
CUse multiple triggers on the same event to split logging tasks
DUse a simple AFTER UPDATE trigger that inserts minimal data into a log table
Step-by-Step Solution
Solution:
  1. Step 1: Consider trigger timing and complexity

    AFTER UPDATE triggers run after the change, so they don't block the main transaction as much as BEFORE triggers.
  2. Step 2: Keep trigger code minimal

    Inserting only essential data into a log table keeps the trigger fast and reduces performance impact.
  3. Final Answer:

    Use a simple AFTER UPDATE trigger that inserts minimal data into a log table -> Option D
  4. Quick Check:

    Simple AFTER triggers with minimal work improve performance [OK]
Quick Trick: Keep triggers simple and after event for better speed [OK]
Common Mistakes:
  • Using BEFORE triggers with complex logic
  • Splitting logging into multiple triggers causing overhead
  • Updating many tables inside triggers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes