MySQL Triggers basic introduction

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.