Mysql trigger operation: mysql trigger operation
Trigger operation: 1. trigger creation: (1 ). create trigger trigger_name before | after trigger_event on table_name for each row trigger_stmt; trigger_event indicates the Operation Event (insert, update, delete); trigger_stmt indicates the execution statement example: create trigger tri_test after insert on t1 for each row insert into t1_log values (USER (), 'insert record into t1', now ()); // after each row of table t1 is inserted, a data entry is inserted in Table t1_log. The data is the content after values. USER () it refers to the current user (built-in function), now () current time. (2 ). create trigger trigger_name before | after trigger_event on table_name for each row BEGIN trigger_stmt end; example: delimiter $ create trigger tri_testafter insert on t1 for each rowBEGINinsert into t1_log values (USER (), 'after insert table t1', now ()); insert into t1_log values (USER (), 'after insert table t1', now (); END $ execute delimiter after execution; restore separator; delimiter refers to switch separator, because multiple statements are separated by semicolons, you need to switch the default delimiter and switch back after the statement is executed. 2. view the trigger: show triggers/G; Query use information_schema in the information_schema database; select * from TRIGGERS where trigger_name = 'tri _ test' \ G; 3. the trigger modification trigger cannot be modified. You can only delete the original trigger and re-create a new trigger. 4. trigger deletion: drop trigger trigger_name;