Use of triggers in Mysql

Source: Internet
Author: User
A conceptual trigger is a special transaction that listens to addition, deletion, and modification operations and triggers addition, deletion, and modification operations. It is mainly used to process some complicated business logic to ensure the linkage of data. It includes four elements: 1. Monitoring location (table) 2. Monitoring event (insertupdatedelete) 3. triggering time (afterbefore) 4. Triggering Event (insertupdated

A conceptual trigger is a special transaction that listens to addition, deletion, and modification operations and triggers addition, deletion, and modification operations. It is mainly used to process some complicated business logic to ensure the linkage of data. It includes four elements: 1. monitoring location (table) 2. monitoring event (insert/update/delete) 3. trigger time (after/before) 4. trigger event (insert/update/d

Concept

A trigger is a special transaction that listens to addition, deletion, and modification operations and triggers addition, deletion, and modification operations. It is mainly used to process some complicated business logic to ensure the linkage of data. It includes four elements: 1. monitoring location (table) 2. monitoring event (insert/update/delete) 3. trigger time (after/before) 4. trigger event (insert/update/delete)

Syntax
Create trigger 'trigger name' 'trigger time (after | before) '': 'On 'TRIGGER location' for each row begin sql1; sql2; sql3; END $

For each row is used to identify the trigger type. because Mysql supports ROW-level triggers and does not support statement triggers, you can only use for each row. Because the trigger uses ';' to differentiate multiple event statements, you need to redefine the delimiters.

Instance

Modify the delimiter to $

Create a trigger

View triggers

Before performing the operation
Table t4 data is as follows:

Table t3 data is as follows:

After performing the corresponding operation

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.