0
0
MySQLquery~5 mins

AFTER INSERT triggers in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an AFTER INSERT trigger in MySQL?
An AFTER INSERT trigger is a special set of instructions that run automatically right after a new row is added to a table. It lets you perform extra actions based on the new data.
Click to reveal answer
beginner
When exactly does an AFTER INSERT trigger execute?
It executes immediately after the new row is successfully inserted into the table, allowing you to react to the insertion.
Click to reveal answer
intermediate
Can an AFTER INSERT trigger modify the row that was just inserted?
No, AFTER INSERT triggers cannot change the inserted row because the insertion is already done. To modify data before insert, use BEFORE INSERT triggers.
Click to reveal answer
beginner
How do you access the new row's data inside an AFTER INSERT trigger?
You use the keyword NEW followed by the column name, like NEW.column_name, to get the values of the inserted row.
Click to reveal answer
beginner
Give a simple example use case for an AFTER INSERT trigger.
You can use it to log every new user added to a users table into a separate audit table, keeping track of who was added and when.
Click to reveal answer
When does an AFTER INSERT trigger run in MySQL?
AWhen a row is deleted
BRight after a new row is inserted
CWhen a row is updated
DBefore a new row is inserted
Which keyword lets you access the new row's data inside an AFTER INSERT trigger?
ANEW
BOLD
CCURRENT
DROW
Can an AFTER INSERT trigger modify the inserted row's data?
AOnly if the trigger is BEFORE INSERT
BYes, always
COnly if the table has no primary key
DNo, it cannot
Which of these is a common use of AFTER INSERT triggers?
ALog inserted data to another table
BPrevent insertion of duplicate rows
CValidate data before insert
DUpdate the inserted row's values
What happens if an AFTER INSERT trigger fails during execution?
AThe insert still succeeds but trigger actions are skipped
BThe database shuts down
CThe insert is rolled back
DThe trigger runs again automatically
Explain what an AFTER INSERT trigger is and when it runs in MySQL.
Think about what happens right after you add a new row to a table.
You got /3 concepts.
    Describe a practical example where you might use an AFTER INSERT trigger.
    Consider how you might keep track of changes automatically.
    You got /3 concepts.