Which of the following is the correct syntax to create a trigger that runs before a row is deleted from a table named Employees?
easy📝 Syntax Q12 of 15
SQL - Triggers
Which of the following is the correct syntax to create a trigger that runs before a row is deleted from a table named Employees?
ACREATE TRIGGER before_delete_employee DELETE ON Employees FOR EACH ROW BEGIN --code END;
BCREATE TRIGGER before_delete_employee AFTER DELETE ON Employees FOR EACH ROW BEGIN --code END;
CCREATE TRIGGER before_delete_employee ON Employees BEFORE DELETE FOR EACH ROW BEGIN --code END;
DCREATE TRIGGER before_delete_employee BEFORE DELETE ON Employees FOR EACH ROW BEGIN --code END;
Step-by-Step Solution
Solution:
Step 1: Identify correct trigger timing syntax
The syntax for a BEFORE DELETE trigger includes 'BEFORE DELETE ON TableName'.
Step 2: Check full syntax correctness
CREATE TRIGGER before_delete_employee BEFORE DELETE ON Employees FOR EACH ROW BEGIN --code END; correctly uses 'CREATE TRIGGER name BEFORE DELETE ON Employees FOR EACH ROW BEGIN ... END;'. Others misuse order or keywords.
Final Answer:
CREATE TRIGGER before_delete_employee BEFORE DELETE ON Employees FOR EACH ROW BEGIN --code END; -> Option D
Quick Check:
BEFORE DELETE ON Table = correct syntax [OK]
Quick Trick:Use BEFORE DELETE ON table for pre-delete triggers [OK]
Common Mistakes:
Placing BEFORE DELETE after ON table
Omitting FOR EACH ROW clause
Using DELETE ON instead of BEFORE DELETE ON
Master "Triggers" in SQL
9 interactive learning modes - each teaches the same concept differently