Recall & Review
beginner
What is a BEFORE INSERT trigger in MySQL?
A BEFORE INSERT trigger is a special procedure that runs automatically before a new row is added to a table. It lets you check or change data before it is saved.
Click to reveal answer
beginner
When exactly does a BEFORE INSERT trigger execute?
It executes right before the new data is inserted into the table, allowing you to modify or validate the data before it is saved.
Click to reveal answer
intermediate
Can a BEFORE INSERT trigger modify the data being inserted?
Yes, it can change the values of the new row before it is saved, for example, to add timestamps or enforce rules.
Click to reveal answer
beginner
How do you access the new row's data inside a BEFORE INSERT trigger?
You use the keyword NEW followed by the column name, like NEW.column_name, to read or change the value.
Click to reveal answer
intermediate
What happens if a BEFORE INSERT trigger signals an error?
The insert operation is stopped, and the new row is not added to the table. This helps keep data clean and valid.
Click to reveal answer
When does a BEFORE INSERT trigger run in MySQL?
✗ Incorrect
A BEFORE INSERT trigger runs right before a new row is added to the table.
How do you refer to the new row's column 'age' inside a BEFORE INSERT trigger?
✗ Incorrect
You use NEW.age to access or modify the new row's 'age' value.
What happens if a BEFORE INSERT trigger raises an error?
✗ Incorrect
If the trigger signals an error, the insert is stopped and the row is not added.
Which of these is a valid use of a BEFORE INSERT trigger?
✗ Incorrect
BEFORE INSERT triggers are often used to set or modify data before saving, like timestamps.
Can a BEFORE INSERT trigger modify multiple columns of the new row?
✗ Incorrect
BEFORE INSERT triggers can change any columns of the new row before it is saved.
Explain what a BEFORE INSERT trigger does and give an example of when you might use it.
Think about how you can change data before saving it.
You got /3 concepts.
Describe how to access and change the data of the new row inside a BEFORE INSERT trigger.
Remember the special keyword for new row data.
You got /3 concepts.