UPDATE Triggers

This lesson shows how to create triggers associated with the UPDATE statement.

We'll cover the following

UPDATE Triggers

Update triggers for a table are automatically executed when an UPDATE is made to the table. These triggers can run before or after the table is updated. Both the NEW and OLD keywords can be used as both values of a column are accessible when using update triggers. When the trigger runs BEFORE the update is performed, the NEW value can be updated while the OLD value cannot be updated. When the trigger runs AFTER the update has been performed, we can only access the NEW and OLD values but cannot update them.

Update triggers cannot be made for views. BEFORE UPDATE triggers can be used to validate data and make necessary corrections or notify user before an update is made to the table. They can also be used to store the new and old values of a column to maintain an update log. AFTER UPDATE triggers can also be used to maintain a change log or to update summary table in the event of an update.



ON table_name



Connect to the terminal below by clicking in the widget. Once connected, the command line prompt will show up. Enter or copy-paste the command ./DataJek/Lessons/48lesson.sh and wait for the mysql prompt to start-up.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.