Fifth Chapter Trigger

Source: Internet
Author: User

Create a trigger

Grammar:

Create TRIGGER Trigger name before|after trigger event on table name for each row execution statement

Note: There can only be one trigger event at the same trigger time, such as the before of insert time can only have one departure event

Create a trigger_time table first:

Mysql> CREATE TABLE Trigger_time (Insert_time datetime);

Create a trigger that has only one execution statement

To create a trigger:

Mysql> CREATE trigger DEPT_TRIG1 before insert on Department for each row insert to Trigger_time values (now ());

In this way, when a record is inserted into the department table, the current time is inserted into the Trigger_time table.

to create a trigger with more than one execution statement

Grammar:

Create TRIGGER Trigger name before|after departure event on indicates for each row

Begin

Execute statement List

End

Note: MySQL defaults to ";" As the end. In the process of creating a trigger, you need to use ";" to solve this problem, you can use "delimiter &&" to change the Terminator to && After the trigger is created, use "delimiter;" Changes the Terminator to ";".

Mysql> delimiter &&

Mysql> CREATE trigger DEPT_TRIG2 after delete on department for each row

Begin

INSERT into Trigger_time values (now ());

INSERT into Trigger_time values (now ());

-End

&&

view triggers

Grammar:

Show triggers;

Delete Trigger

Grammar:

Drop trigger trigger name;

Fifth Chapter 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.