MySQL Learning--the action of a trigger

Source: Internet
Author: User

One, why use trigger 1. What is a trigger

Triggers are one of the MySQL database objects that need to be declared, executed, etc., the execution of the trigger is not called by the program, nor is it started manually, but is triggered and activated by the event to implement.
Some of these things include: DELETE statement, insert statement, UPDATE statement.

Ii. creating a Trigger 1. Create a trigger that has an execution statement

Basic syntax

CREATE TRIGGER trigger_name    BEFORE | AFTER trigger_event        ON table_name FOR EACH ROW trigger_stmt

The Before and after parameters specify the execution time of the trigger, the Trigger_event parameter specifies the trigger event, and the TRIGGER_STMT parameter represents the statement executed after the trigger is activated.

2. Create a trigger with more than one execution statement

Basic syntax

CREATE TRIGGER trigger_name    BEFORE | AFTER trigger_event        ON table_name FOR EACH ROW BEGIN trigger_stmt END

TRIGGER_STMT is a multiple SQL statement, generally used ";" Symbol as the end symbol of the statement, you can use the Delemiter statement.

//把结束符改为“$$”DELEMITER$$
Third, view the trigger

Basic syntax

    • Way One:

      SHOW TRIGGERS \G
    • Way two:

      USE information_schema;SELECT * FORM triggers \GSELECT * FROM triggers WHERE TRIGGER_NAME="trigger_name" \G
Iv. deleting triggers

Basic syntax

DROP TRIGGER trigger_name;

MySQL Learning--the action of a 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.