MySQL database trigger

Source: Internet
Author: User

MySQL database trigger

1. Trigger with only one row of statements executed

Trigger triggers are events that trigger certain operations, such as insert, delete, and update.

For example:

Create trigger t_user_trig before insert
On t_user for each row
Insert into trigger_time values (now ());

Create a trigger named t_user_trig to insert the current time to the trigger_time table when inserting the t_user table.

Test:

Insert into t_user values (2, 'wang ', 0, 'abcdef', now (), 'A ');

Select * from trigger_time;


2. Trigger with multi-row statement execution

Example:

Delimiter &&
Create trigger t_user_trig_del after delete
On t_user for each row
Begin
Insert into trigger_time values ('2017-01-01 10:10:00 ');
Insert into trigger_time values ('2017-01-01 11:11:00 ');
End
&&
Delimiter;

Create a trigger named t_user_trig_del. After deleting the t_user record in the table, two insert statements are executed.

Select * from trigger_time;


3. View triggers

Select * from information_schema.triggers where trigger_name = 't_user_trig ';


4. delete a trigger


Related Article

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.