Trigger (Trigger)
1. Role: Monitor a situation and trigger an action.
The trigger can monitor the increase, deletion and change of the table, and make the operation of adding, deleting and changing.
2. Create TRIGGER Syntax: (Requires early modification of Terminator: delimiter Terminator)
CREATE TRIGGER trigger_name
After/before
increase, delete, change on Table name
F or each ROM
B Egin SQL statements;
E nd End Character
Trigger Name
Trigger Time
A the difference between fter and before:
A fter: complete the data operation before triggering.
B Efore: Actions that trigger the data before the operation is monitored
Events monitored by triggers
Trigger Watch Locations
Events triggered by triggers
3. the value of the trigger reference row:
1. for inset, the newly added line is represented by new.
the values for each row in the line are new. Column name
2. For delete, there was a row, then deleted, to refer to the deleted row, with Old . Column name
3. for update, the modified row is modified by using the old. Column name
When modified, use the new column name
4. To delete a trigger:
D ROP Trigger trigger name
This article is from the "Learning and Exchange" blog, please be sure to keep this source http://chenhaolinux.blog.51cto.com/9609922/1710811
MySQL Learning Note (12) trigger (trigger)