Bird
0
0

You want to create an audit trigger that logs INSERT and UPDATE actions on the customers table into customer_audit. Which approach correctly handles both actions in one trigger?

hard📝 Best Practice Q15 of 15
SQL - Triggers
You want to create an audit trigger that logs INSERT and UPDATE actions on the customers table into customer_audit. Which approach correctly handles both actions in one trigger?
ACreate two separate triggers: one AFTER INSERT and one AFTER UPDATE
BCreate one AFTER INSERT trigger and ignore UPDATE actions
CCreate one trigger AFTER INSERT OR UPDATE and use conditional logic inside
DCreate a BEFORE DELETE trigger to log INSERT and UPDATE
Step-by-Step Solution
Solution:
  1. Step 1: Understand trigger event options

    Some SQL systems allow triggers on multiple events like AFTER INSERT OR UPDATE.
  2. Step 2: Use conditional logic inside trigger

    Inside the trigger, check if the event is INSERT or UPDATE to log accordingly.
  3. Step 3: Compare options

    Create one trigger AFTER INSERT OR UPDATE and use conditional logic inside correctly combines both events in one trigger with logic; Create two separate triggers: one AFTER INSERT and one AFTER UPDATE uses two triggers, which is valid but not one trigger.
  4. Final Answer:

    Create one trigger AFTER INSERT OR UPDATE and use conditional logic inside -> Option C
  5. Quick Check:

    One trigger can handle multiple events with conditions [OK]
Quick Trick: Use AFTER INSERT OR UPDATE with IF inside trigger [OK]
Common Mistakes:
  • Trying to log UPDATE in an INSERT-only trigger
  • Using BEFORE DELETE for INSERT/UPDATE logging
  • Not using conditional logic inside multi-event triggers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes