0
0
SQLquery~5 mins

BEFORE trigger execution in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ABefore the data change happens
BAfter the data change happens
COnly when data is deleted
DOnly when data is selected
Which of these can a BEFORE trigger do?
ASend an email after saving
BModify data before saving
CCreate a new table
DDrop the database
If you want to prevent bad data from being saved, which trigger should you use?
ABEFORE trigger
BAFTER trigger
CINSTEAD OF trigger
DNO trigger
Which SQL statement is used to create a BEFORE trigger?
ACREATE VIEW ... BEFORE
BCREATE PROCEDURE ... BEFORE
CCREATE FUNCTION ... BEFORE
DCREATE TRIGGER ... BEFORE
Can a BEFORE trigger run on UPDATE operations?
AOnly on DELETE
BNo
CYes
DOnly on INSERT
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.