Create trigger trigger_name trigger_time trigger_event on tbl_name <br/> for each row begin <br/> [statement] <br/> end <br/>
Trigger_name: trigger name
Trigger_time: departure time [after: after execution, before: before execution]
Trigger_event: Start event [insert, update, delete]
Tbl_name: for a table
Statement: Expression
For example:
When a new record is added to a table, enter its orderid number in the other table.
Create trigger trigger_name after insert on table_name <br/> begin <br/> insert into other_table_name set keyname = new. orderid, keyValue = new. orderid; <br/> end
New: refers to the order record after insertion. You can reference the inserted data by using the new. method.
For example:
When updating a field in a table, update or update another table based on whether the conditions are met.
Create trigger trigger_name after update on table_name <br/> begin <br/> declare counts int (1); <br/> if old. ordstate = 0 & New. ordstate = 1 then <br/> select count (*) into counts from other_table_name where keyname = old. orderid; <br/> If counts = 0 then <br/> insert into listen_ticket set keyname = new. orderid, keyValue = new. orderid; <br/> end if; <br/> end
Declare: defines Variables
Old: unupdated data information
Into variable: Assign the query return value to a variable.