Mysql trigger, mysql trigger instance
Trigger 1. Definition: a specific operation is triggered by insert, update, delete, and other events. The trigger can trigger multiple execution statements. Note: triggers cannot contain keywords such as start transaction, commit, or rollback, nor call statements. 1. Format: create trigger name berfor | after trigger event on table name for each row execution statement 2. format: mysql> DELIMITER & mysql> create trigger name berfor | after trigger event on table name for each row begin execution statement; end & mysql> DELIMITER; note: for each row indicates that any operation on a record meets the trigger event, this trigger will be triggered. by default, MYSQL uses ";" as the end statement. You need to use a semicolon to create a trigger. To solve this problem, you can use the delimiter statement, for example, "delimiter &". You can change the end symbol to "&". after the trigger is created, run the "delimiter;" command to change the end symbol to a semicolon. Only one trigger can be created for a table with the same trigger time. Ii. query trigger 1. Statement: show triggers \ G. This statement queries all triggers in the specified database. 2. query the triggers table in the information_schema database: select * from information_schema.triggers where trigger_name = 'trigger name' \ G 3. Delete trigger drop trigger name; 4. trigger application 1. For insert, the new row uses new to represent the value of each column in the row. create trigger tg2after insert on ofor each rowbeginupdate g set num = num-new.much where id = new. gid; end $2. For delete, the row to be deleted is represented by old. 3. For update, the old value of the row to be updated is represented by old, use new to create trigger tg2after insert on ofor each rowbeginupdate g set num = num + old. much-new.much where id = old. gid; end $