Bird
0
0

Which SQL statement correctly creates a BEFORE INSERT trigger named trg_update_timestamp on the orders table?

easy📝 Syntax Q3 of 15
SQL - Triggers
Which SQL statement correctly creates a BEFORE INSERT trigger named trg_update_timestamp on the orders table?
ACREATE TRIGGER trg_update_timestamp BEFORE INSERT ON orders FOR EACH ROW SET NEW.updated_at = CURRENT_TIMESTAMP;
BCREATE TRIGGER trg_update_timestamp AFTER INSERT ON orders FOR EACH ROW BEGIN SET NEW.updated_at = CURRENT_TIMESTAMP; END;
CCREATE TRIGGER trg_update_timestamp BEFORE INSERT ON orders FOR EACH ROW BEGIN SET NEW.updated_at = CURRENT_TIMESTAMP; END;
DCREATE TRIGGER trg_update_timestamp ON orders BEFORE INSERT FOR EACH ROW BEGIN SET NEW.updated_at = CURRENT_TIMESTAMP; END;
Step-by-Step Solution
Solution:
  1. Step 1: Identify trigger timing and event

    The trigger is BEFORE INSERT on the orders table.
  2. Step 2: Check syntax for trigger body

    Standard SQL requires BEGIN ... END block for multiple statements or SET commands.
  3. Step 3: Evaluate options

    CREATE TRIGGER trg_update_timestamp BEFORE INSERT ON orders FOR EACH ROW BEGIN SET NEW.updated_at = CURRENT_TIMESTAMP; END; correctly uses BEFORE INSERT, FOR EACH ROW, and a BEGIN ... END block with SET NEW.updated_at = CURRENT_TIMESTAMP;
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    Trigger timing and syntax match standard SQL [OK]
Quick Trick: Use BEGIN...END with SET in BEFORE INSERT triggers [OK]
Common Mistakes:
  • Omitting BEGIN...END block when required
  • Using AFTER INSERT when BEFORE INSERT is needed
  • Incorrect trigger syntax order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes