Understanding Triggers

A trigger is a stored database object that contains a series of SQL commands, set to activate automatically when certain events take place.

Each trigger is associated with a table. You can create a trigger that will fire when an INSERT, UPDATE, or DELETE takes place on the named table.

REPLACE

Remember that when you use a REPLACE statement, MySQL actually performs a DELETE followed by an INSERT. Therefore, the REPLACE command will activate a DELETE trigger if the row already exists and will always activate an INSERT trigger.

Using Triggers

Triggers are used to perform more database operations when a certain type of database ...

Get Sams Teach Yourself MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.