0
0
MySQLquery~5 mins

BEFORE INSERT triggers in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ABefore a new row is inserted
BAfter a new row is inserted
CWhen a row is updated
DWhen a row is deleted
How do you refer to the new row's column 'age' inside a BEFORE INSERT trigger?
AOLD.age
BNEW.age
Cage
DNEW['age']
What happens if a BEFORE INSERT trigger raises an error?
AThe insert is canceled
BThe insert continues anyway
CThe trigger is ignored
DThe row is updated instead
Which of these is a valid use of a BEFORE INSERT trigger?
ADelete rows from another table
BUpdate existing rows after insert
CAutomatically set a creation timestamp
DDrop the table
Can a BEFORE INSERT trigger modify multiple columns of the new row?
AOnly if the table has a primary key
BNo, it can only read data
CNo, it can only modify one column
DYes, it can modify any columns before insert
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.