Database triggers (Trigger) a bit of the use of experience _ database other

Source: Internet
Author: User
(1) for the more complicated constraint of data service level across multiple tables, the trigger can be used to replace a large number of background judgment code, which is more efficient and convenient.
(2) If you want to use triggers to assist business logic, you cannot design triggers with a single focus on the changes in the content of the database, and you must closely incorporate all the places in the business model that are involved in the table, because it is possible that inconsistent logical processing leads to the omission of some branching conditions for the triggers In fact, in this case, if there is a better way, do not recommend the use of triggers, because involved in too much business logic content, the trigger design and writing difficulties, can not give full play to its advantages of convenient and efficient.
(3) Given that the trigger is actually running, is included in a database transaction, so we write a complete processing branch, we can completely rely on its implementation, a large number of concurrent cases, the database will automatically handle the operation of the various transactions, do not worry about the performance and correctness of the trigger.
(4) Different execution statements in the same transaction, if the action in the following statement triggers the trigger of the corresponding table, the contents of the result list after the preceding statement can be viewed within the trigger, so the order of the actions of the multiple statements in the object is considered clearly when using the trigger.
(5) If we use the form of Trigger + datasheet to perform some statistical operations on the data, in order to guarantee the logic integrity of the trigger, it is best to check the database task in a timely manner, because the trigger can handle the operation of a program. But there is sometimes nothing to do with artificial database operations, therefore, in order to avoid such mistakes, it is necessary to make regular checks of statistical results to ensure the correctness of the data, of course, if possible, try not to use this method, but in some personalized projects, for some special reasons, may be applied.
(6) We can indirectly debug the trigger by updating the datasheet, and of course, we can help with debugging by adding "Special Log Update statements" in the trigger.

Finally, the so-called "good steel used in the blade", triggers in a number of special applications, will greatly simplify our development workload, and improve processing efficiency, but it does not apply to all kinds of application environment, so we use, we must be cautious, but also weigh the pros and cons.

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.