Summary of mysql event calling stored procedure, mysql event Stored Procedure

Source: Internet
Author: User

Summary of mysql event calling stored procedure, mysql event Stored Procedure

For the first time I wrote an event to call the stored procedure, I found some information on the Internet. I would like to summarize it and consolidate it:

There are three main types of event calling stored procedures:

(1) Create an event and execute it immediately. Call the Stored Procedure

Create event if not exists Event_Stat_Daily
On schedule EVERY 1 DAY
On completion preserve
Do call cp_Stat_VideoData ();

(2) regularly execute events every day and call the Stored Procedure

Create event Event_Stat_Daily
On schedule every 1 day starts '2017-03-01 02:00:00'
ON COMPLETION PRESERVE
ENABLE
DO call cp_Stat_VideoData ();

(3) logical operations in the event are directly performed without calling methods or stored procedures

 

DELIMITER | create event e5 on schedule every 1 day starts '2017-03-01 02:00:00 'on completion preserve do begin declare yestday date; set yestday = date (date_add (NOW (), interval-1 day); if exists (select Id from Stat_VideoHits where AddDate = yestday) THEN delete from Stat_VideoHits where AddDate = yestday; end if;

Insert into Stat_VideoHits (Id, VideoId, Times, AddDate) select uuid (), VideoId, COUNT (1), AddDate from Coll_VideoHits where AddDate = yestday group by VideoId;

DELETE from Sum_VideoHits;

Insert into Sum_VideoHits (Id, VideoId, Times, UpdateDate) select uuid (), VideoId, sum (Times), now () from Stat_VideoHits group by VideoId;

END | DELIMITER;

 

This article mainly from: http://www.cnblogs.com/zoro-zero/p/6511203.html

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.