Bird
0
0

Which of the following correctly creates a row-level BEFORE INSERT trigger on a table named employees in PostgreSQL?

easy📝 Syntax Q3 of 15
PostgreSQL - Triggers in PostgreSQL
Which of the following correctly creates a row-level BEFORE INSERT trigger on a table named employees in PostgreSQL?
ACREATE TRIGGER emp_before_insert BEFORE INSERT ON employees FOR EACH ROW EXECUTE FUNCTION trg_func();
BCREATE TRIGGER emp_before_insert BEFORE INSERT ON employees FOR EACH STATEMENT EXECUTE FUNCTION trg_func();
CCREATE TRIGGER emp_before_insert AFTER INSERT ON employees FOR EACH ROW EXECUTE FUNCTION trg_func();
DCREATE TRIGGER emp_before_insert AFTER INSERT ON employees FOR EACH STATEMENT EXECUTE FUNCTION trg_func();
Step-by-Step Solution
Solution:
  1. Step 1: Identify trigger timing and event

    The question asks for a BEFORE INSERT trigger, so the timing is BEFORE and event is INSERT.
  2. Step 2: Determine trigger level

    Row-level triggers use FOR EACH ROW, statement-level use FOR EACH STATEMENT.
  3. Step 3: Match syntax

    CREATE TRIGGER emp_before_insert BEFORE INSERT ON employees FOR EACH ROW EXECUTE FUNCTION trg_func(); uses BEFORE INSERT, FOR EACH ROW, and executes the function correctly.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Trigger timing and level keywords must match the requirement [OK]
Quick Trick: Row-level triggers use FOR EACH ROW, statement-level FOR EACH STATEMENT [OK]
Common Mistakes:
  • Using FOR EACH STATEMENT instead of FOR EACH ROW for row-level triggers
  • Confusing BEFORE and AFTER timing
  • Omitting EXECUTE FUNCTION keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes