Bird
0
0

Which of the following is the correct syntax to create a BEFORE INSERT trigger on a table named users?

easy📝 Syntax Q12 of 15
PostgreSQL - Triggers in PostgreSQL
Which of the following is the correct syntax to create a BEFORE INSERT trigger on a table named users?
ACREATE TRIGGER trg BEFORE INSERT ON users CALL func();
BCREATE TRIGGER trg AFTER INSERT ON users EXECUTE FUNCTION func();
CCREATE TRIGGER trg BEFORE INSERT INTO users EXECUTE FUNCTION func();
DCREATE TRIGGER trg BEFORE INSERT ON users EXECUTE FUNCTION func();
Step-by-Step Solution
Solution:
  1. Step 1: Check trigger timing and event

    The trigger must be BEFORE INSERT on the table users.
  2. Step 2: Verify syntax for calling function

    PostgreSQL uses EXECUTE FUNCTION to call the trigger function.
  3. Final Answer:

    CREATE TRIGGER trg BEFORE INSERT ON users EXECUTE FUNCTION func(); -> Option D
  4. Quick Check:

    Correct syntax uses BEFORE INSERT ON and EXECUTE FUNCTION [OK]
Quick Trick: Use BEFORE INSERT ON table EXECUTE FUNCTION func() [OK]
Common Mistakes:
  • Using AFTER instead of BEFORE
  • Writing INTO instead of ON
  • Using CALL instead of EXECUTE FUNCTION

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes