Basically, MySQL trigger is a set of statements stored in the database catalog. This database object is always associated with a table that is defined to be activated when a particular kind of event occurs for that table. In other sense, we can say that MySQL trigger is a special kind of stored procedure. Its main difference with the stored procedure is that it is not called directly like a stored procedure. It is called automatically when a data modification even against the table occurs. The trigger can be executed when you run one of the following MySQL statements on the table: INSERT, UPDATE, and DELETE and it can be invoked before or after the event. Triggers appear to execute quietly without the user even knowing of their existence. They cannot include COMMIT or ROLLBACK statements.
Triggering events are basically the action of time i.e. when the trigger activates. Followings are the triggering events related to MySQL triggers −
- INSERT − As its name suggests, this indicates the trigger event is related to the insertion of data in MySQL table. In this case, the trigger would be triggered either before or after the insertion of data happens.
- DELETE − As its name suggests, this indicates the trigger event is related to the deletion of data in MySQL table. In this case, the trigger would be triggered either before or after deletion of data happens.
- UPDATE − As its name suggests, this indicates the trigger event is related to the update of data in MySQL table. In this case, the trigger would be triggered either before or after an updating of data happens.