Trigger is an action triggered by an event. These events include INSERT statements, UPDATE statements, and DELETE statements. When the database executes these events, the trigger is activated to perform the appropriate action.
"1" has only one execution statement
Create trigger Trig_booksum after Inserton T_book for each rowupdate t_booktype set booksum=booksum+1 where New.booktypeid =t_booktype.id;
When inserted, the number of books in the book category plus 1
"2" Multiple execution statements
Delimiter &&
... body
&&
delimiter;
Create a T_log table to save the log (visual creation),
Delimiter &&create trigger Trig2 after Deleteon T_book for each rowbeginupdate T_booktype set booksum=booksum-1 WH ere Old.booktypeid=t_booktype.id;insert into t_log values (Null,now (), "delete a message in book"); end&&delimiter;
Delete from T_book where id=10; view Booksum and T_log logs
MySQL trigger "over variable new old"