MySQL trigger "over variable new old"

Source: Internet
Author: User

Trigger is an action triggered by an event. These events include INSERT statements, UPDATE statements, and DELETE statements. When the database executes these events, the trigger is activated to perform the appropriate action.

"1" has only one execution statement

Create trigger Trig_booksum after Inserton T_book for each rowupdate t_booktype set booksum=booksum+1 where New.booktypeid =t_booktype.id;

When inserted, the number of books in the book category plus 1

"2" Multiple execution statements

Delimiter &&

... body

&&
delimiter;

Create a T_log table to save the log (visual creation),

Delimiter &&create trigger Trig2 after Deleteon T_book for each rowbeginupdate T_booktype set booksum=booksum-1 WH ere Old.booktypeid=t_booktype.id;insert into t_log values (Null,now (), "delete a message in book"); end&&delimiter;

Delete from T_book where id=10; view Booksum and T_log logs

MySQL trigger "over variable new old"

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.