MySQL database Triggers

Source: Internet
Author: User

MySQL database Triggers

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 inserton t_user for each rowinsert 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 deleteon t_user for each rowbegininsert 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 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

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.