Recall & Review
beginner
What is a BEFORE trigger in SQL?
A BEFORE trigger is a special procedure that runs automatically before an INSERT, UPDATE, or DELETE operation on a table. It lets you check or change data before it is saved.
Click to reveal answer
beginner
When does a BEFORE trigger execute?
A BEFORE trigger executes just before the data modification happens on the table. This means it runs before the new data is inserted, updated, or deleted.
Click to reveal answer
intermediate
Can a BEFORE trigger modify the data being inserted or updated?
Yes, a BEFORE trigger can change the data before it is saved to the table. For example, it can set default values or correct data formats.
Click to reveal answer
intermediate
Why use a BEFORE trigger instead of an AFTER trigger?
Use a BEFORE trigger to validate or modify data before it is saved. AFTER triggers run after the data change, so they can't stop or change the data before saving.
Click to reveal answer
intermediate
Example of a simple BEFORE INSERT trigger in SQL?
CREATE TRIGGER set_default_status BEFORE INSERT ON orders FOR EACH ROW BEGIN IF NEW.status IS NULL THEN SET NEW.status = 'pending'; END IF; END;
Click to reveal answer
When does a BEFORE trigger run in SQL?
✗ Incorrect
A BEFORE trigger runs before the data is inserted, updated, or deleted.
Which of these can a BEFORE trigger do?
✗ Incorrect
BEFORE triggers can modify data before it is saved to the table.
If you want to prevent bad data from being saved, which trigger should you use?
✗ Incorrect
BEFORE triggers run before data is saved, so they can stop or fix bad data.
Which SQL statement is used to create a BEFORE trigger?
✗ Incorrect
CREATE TRIGGER with BEFORE specifies a trigger that runs before data changes.
Can a BEFORE trigger run on UPDATE operations?
✗ Incorrect
BEFORE triggers can run on INSERT, UPDATE, or DELETE operations.
Explain what a BEFORE trigger is and when it runs.
Think about what happens before saving data.
You got /3 concepts.
Describe a practical use case for a BEFORE trigger in a database.
Imagine you want to fix or check data before it is stored.
You got /3 concepts.