MySQL database triggers

Source: Internet
Author: User

First, only one row executes the trigger of the statement

Trigger triggers are events that trigger certain actions, including insert/delete/update, etc.

For example:

Create Trigger T_user_trig before insert
On T_user for each row
INSERT into Trigger_time values (now ());

This means that you create a trigger named T_user_trig that inserts the current time into the Trigger_time table when you perform an insert operation on table T_user.

Test it:

INSERT into T_user values (2, ' Wang ', 0, ' abcdef ', now (), ' a ');

SELECT * from Trigger_time;


II. triggers with multiple lines of execution statements

Example:

Delimiter &&
Create Trigger T_user_trig_del after delete
On T_user for each row
Begin
INSERT into trigger_time values (' 2000-01-01 10:10:00 ');
INSERT into trigger_time values (' 2001-01-01 11:11:00 ');
End
&&
Delimiter

Create a trigger named T_user_trig_del after you delete a table T_user record, two INSERT statements are executed.

SELECT * from Trigger_time;


Third, view the trigger

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


Iv. deleting triggers


MySQL database 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.