Bird
0
0

Which of the following is the correct syntax to create an INSTEAD OF trigger on a view named my_view for INSERT operations?

easy📝 Syntax Q12 of 15
PostgreSQL - Triggers in PostgreSQL
Which of the following is the correct syntax to create an INSTEAD OF trigger on a view named my_view for INSERT operations?
ACREATE TRIGGER trg_instead_of_insert ON my_view INSTEAD OF INSERT FOR EACH ROW EXECUTE FUNCTION trg_func();
BCREATE TRIGGER trg_instead_of_insert INSTEAD OF INSERT ON my_view EXECUTE FUNCTION trg_func();
CCREATE TRIGGER trg_instead_of_insert ON my_view INSTEAD OF INSERT EXECUTE FUNCTION trg_func();
DCREATE TRIGGER trg_instead_of_insert ON my_view BEFORE INSERT EXECUTE FUNCTION trg_func();
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct trigger syntax in PostgreSQL

    The syntax requires specifying the trigger name, the event timing (INSTEAD OF), the event type (INSERT), the target (ON my_view), and the function to execute.
  2. Step 2: Identify the full correct syntax

    CREATE TRIGGER trg_instead_of_insert ON my_view INSTEAD OF INSERT FOR EACH ROW EXECUTE FUNCTION trg_func(); correctly includes "ON my_view INSTEAD OF INSERT FOR EACH ROW EXECUTE FUNCTION trg_func();" which is the proper syntax for INSTEAD OF triggers on views.
  3. Final Answer:

    CREATE TRIGGER trg_instead_of_insert ON my_view INSTEAD OF INSERT FOR EACH ROW EXECUTE FUNCTION trg_func(); -> Option A
  4. Quick Check:

    INSTEAD OF triggers need FOR EACH ROW and correct order [OK]
Quick Trick: INSTEAD OF triggers use 'FOR EACH ROW' and 'EXECUTE FUNCTION' [OK]
Common Mistakes:
  • Placing INSTEAD OF before ON
  • Omitting FOR EACH ROW
  • Using BEFORE instead of INSTEAD OF

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes