One, why use trigger 1. What is a trigger
Triggers are one of the MySQL database objects that need to be declared, executed, etc., the execution of the trigger is not called by the program, nor is it started manually, but is triggered and activated by the event to implement.
Some of these things include: DELETE statement, insert statement, UPDATE statement.
Ii. creating a Trigger 1. Create a trigger that has an execution statement
Basic syntax
CREATE TRIGGER trigger_name BEFORE | AFTER trigger_event ON table_name FOR EACH ROW trigger_stmt
The Before and after parameters specify the execution time of the trigger, the Trigger_event parameter specifies the trigger event, and the TRIGGER_STMT parameter represents the statement executed after the trigger is activated.
2. Create a trigger with more than one execution statement
Basic syntax
CREATE TRIGGER trigger_name BEFORE | AFTER trigger_event ON table_name FOR EACH ROW BEGIN trigger_stmt END
TRIGGER_STMT is a multiple SQL statement, generally used ";" Symbol as the end symbol of the statement, you can use the Delemiter statement.
//把结束符改为“$$”DELEMITER$$
Third, view the trigger
Basic syntax
Iv. deleting triggers
Basic syntax
DROP TRIGGER trigger_name;
MySQL Learning--the action of a trigger