A trigger is a special kind of stored procedure that automatically executes when an event occurs in the database server. DML triggers execute when a user tries to modify data through a data manipulation language (DML) event. DML events are INSERT, UPDATE, or DELETE statements on a table or view.
MySQL trigger syntax
In order to create a new trigger, you use the statementCREATE TRIGGER
. The following illustrates the syntax of the CREATE TRIGGER
statement:
CREATE TRIGGER trigger_name trigger_time trigger_event
ON table_name
FOR EACH ROW
BEGIN
…
END;
Let’s examine the syntax above in more detail.