Basic Introduction:1. Triggers allow you to perform certain actions when executing insert,update,delete statements. And you can specify in MySQL whether to trigger before or after the SQL statement is executed. 2. The trigger does not return a value. 3. Triggers can reduce communication between the client and the server, so triggers can simplify application logic and can improve performance. 4.mysql triggers are very simple to implement, so they are also limited in functionality.
Precautions :1. For each event of each table, you can define a maximum of one trigger (i.e. no more than two triggers defined on insert); 2.MySQL only Supports "Row-based triggering"-that is, the trigger is always for one record, not for the entire SQL statement. If you change the data set very large, the efficiency will be very low.
limitations of Triggers:1. Triggers can obscure the work behind a server, behind a simple SQL statement, because the trigger may contain a lot of unseen work. For example, a trigger might update another related table, and the trigger would double the number of records affected by this SQL. 2. The problem with triggers is difficult to troubleshoot and can be difficult to analyze and locate if a performance issue is related to a trigger. 3. Triggers can cause deadlocks or lock waits. If the trigger fails, the original SQL statement will fail. If you do not realize that this is a trigger, it is hard to understand what the error code is meant to be thrown by the server.
Description:1. Triggers do not necessarily guaranteethe atomic nature of the update. The triggers on the 2.Innodb table are in the sameTransactions, so the actions they perform are atomic, and both the original operation and the trigger operation succeed or fail at the same time. If you build triggers on the InnoDB table to check the consistency of the data, you need to be particularly careful
MVCC, a little careless, you will get the wrong result. 3. Triggers are useful, especially when implementing constraints, system maintenance tasks, and updating anti-normalized data. 4. You can also try a trigger to record the data change log.
MySQL Triggers basic introduction