Bird
0
0

Which of the following is the correct syntax to create an AFTER DELETE trigger on a table named 'employees'?

easy📝 Syntax Q3 of 15
PostgreSQL - Triggers in PostgreSQL
Which of the following is the correct syntax to create an AFTER DELETE trigger on a table named 'employees'?
ACREATE TRIGGER trg_after_delete AFTER DELETE ON employees FOR EACH ROW EXECUTE FUNCTION log_delete();
BCREATE TRIGGER trg_after_delete BEFORE DELETE ON employees FOR EACH ROW EXECUTE FUNCTION log_delete();
CCREATE TRIGGER trg_after_delete AFTER DELETE ON employees FOR EACH STATEMENT EXECUTE FUNCTION log_delete();
DCREATE TRIGGER trg_after_delete AFTER UPDATE ON employees FOR EACH ROW EXECUTE FUNCTION log_delete();"
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct timing and event

    The trigger must be AFTER DELETE on the 'employees' table.
  2. Step 2: Confirm syntax for row-level trigger

    FOR EACH ROW is correct for row-level triggers; the function name is log_delete().
  3. Final Answer:

    CREATE TRIGGER trg_after_delete AFTER DELETE ON employees FOR EACH ROW EXECUTE FUNCTION log_delete(); -> Option A
  4. Quick Check:

    Correct AFTER DELETE syntax = CREATE TRIGGER trg_after_delete AFTER DELETE ON employees FOR EACH ROW EXECUTE FUNCTION log_delete(); [OK]
Quick Trick: AFTER triggers use EXECUTE FUNCTION with correct event and timing [OK]
Common Mistakes:
  • Using BEFORE instead of AFTER
  • Using FOR EACH STATEMENT instead of FOR EACH ROW
  • Mixing UPDATE event with DELETE trigger

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes