To create a trigger:
create [or replace] trigger Trigger_name
Before|after
Event1 [or Event2 or event3 ...]
On table_name [for each row]
Begin
Statement
...
End
Event is typically a DML operation such as INSERT, delete, or update
Description
The meaning of the for every row is that in the statement of a single action table, each operation succeeds one line at a time, and if it is not written, it is a table-level trigger, then it is triggered only once for any number of rows;
Triggers are divided into statement-level triggers and row-level triggers
A statement-level trigger is a single DML statement executed every time the trigger executes
Row-level triggers are triggered several times by each DML operation that affects several records (for each row)
Row-level triggers have new and old values for each record because of the data changes involved in each record
Key words:
: NEW and: Old use method and meaning,
New only appears at insert and update when old is only present at update and delete. At insert time, new represents the newly inserted row data, and new at update indicates the data to be replaced,
Old indicates the original data row to be changed, and delete is the data to be deleted.
To view a trigger:
Show triggers;
Viewing trigger information in the Trggers table
SELECT * FROM Infomation_schema triggers where condition;
To delete a trigger:
Drop trigger [schema_name.] Trigger_name;
Learning notes-mysql_ triggers