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