MySQL Database learning eight triggers operation

Source: Internet
Author: User

8.1 Triggers

When a table changes, some processing occurs automatically. For example, when each additional student record is added to the student table, the total number of students must be changed at the same time, and the phone number should be checked for correct format and address abbreviation.

  The following statement activates the trigger:

    • Delete statement.
    • Insert statement.
    • UPDATE statement.

MySQL 5 starts supporting trigger database objects.

8.2 Creating a Trigger

CREATE TRIGGER trigger_name    before| After trigger_event on table_name for each         ROW trigger_stmt;

Trigger_name: Trigger name.

Trigger_event:delete, insert, and update.

TABLE_NAME: The table that triggered the event.

TRIGGER_STMT: The statement executed after the trigger is activated.

To create a trigger that contains multiple execution statements

DELIMITER $$//set End symbol to $ $CREATE TRIGGER trigger_name    before| After trigger_event on         table_name for each ROW            BEGIN            trigger_stmt//Multiple execution statements, separated by            END            $ $DELIMITER ;//restore the end symbol setting to;

8.3 Viewing triggers

Trigger, Event, Table, Statement, Timing

SHOW TRIGGERS \g
Use INFORMATION_SCHEMA; SELECT * FROM triggers "WHERE trigger_name= ' trigger_name '" \g

8.4 Deleting a Trigger

DROP TRIGGER trigger_name;

  

MySQL Database learning eight triggers 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.