Learning notes-mysql_ triggers

Source: Internet
Author: User

To create a trigger:

create [or replace] trigger Trigger_name

Before|after

Event1 [or Event2 or event3 ...]

On table_name [for each row]

Begin

Statement

...

End

Event is typically a DML operation such as INSERT, delete, or update

Description

The meaning of the for every row is that in the statement of a single action table, each operation succeeds one line at a time, and if it is not written, it is a table-level trigger, then it is triggered only once for any number of rows;

Triggers are divided into statement-level triggers and row-level triggers

A statement-level trigger is a single DML statement executed every time the trigger executes

Row-level triggers are triggered several times by each DML operation that affects several records (for each row)

Row-level triggers have new and old values for each record because of the data changes involved in each record

Key words:

: NEW and: Old use method and meaning,

New only appears at insert and update when old is only present at update and delete. At insert time, new represents the newly inserted row data, and new at update indicates the data to be replaced,

Old indicates the original data row to be changed, and delete is the data to be deleted.

To view a trigger:

Show triggers;

Viewing trigger information in the Trggers table

SELECT * FROM Infomation_schema triggers where condition;

To delete a trigger:

Drop trigger [schema_name.] Trigger_name;



Learning notes-mysql_ triggers

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.