MySQL Learning Note (12) trigger (trigger)

Source: Internet
Author: User

Trigger (Trigger)

1. Role: Monitor a situation and trigger an action.

The trigger can monitor the increase, deletion and change of the table, and make the operation of adding, deleting and changing.

2. Create TRIGGER Syntax: (Requires early modification of Terminator: delimiter Terminator)

CREATE TRIGGER trigger_name

After/before

increase, delete, change on Table name

F or each ROM

B Egin SQL statements;

E nd End Character

Trigger Name

Trigger Time

A the difference between fter and before:

A fter: complete the data operation before triggering.

B Efore: Actions that trigger the data before the operation is monitored

Events monitored by triggers

Trigger Watch Locations

Events triggered by triggers

3. the value of the trigger reference row:

1. for inset, the newly added line is represented by new.

the values for each row in the line are new. Column name  

2. For delete, there was a row, then deleted, to refer to the deleted row, with Old . Column name

3. for update, the modified row is modified by using the old. Column name

When modified, use the new column name

4. To delete a trigger:

D ROP Trigger trigger name


This article is from the "Learning and Exchange" blog, please be sure to keep this source http://chenhaolinux.blog.51cto.com/9609922/1710811

MySQL Learning Note (12) trigger (trigger)

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.