Database

Run Multiple query in a single Scheduled Event in MYSQL

Running a Scheduled Event in Mysql Database is pretty easy, read the tutorial from my previous article here.  From previous article we can see that MySQL scheduled event can only execute 1 query in a time. but, by modify your code you can bypass that limit and run multiple query in a single scheduled event.

The Query: 

delimiter |
CREATE EVENT addTimestamp
 ON SCHEDULE AT '2016-06-19 10:00:00'
 DO
 BEGIN
 TRUNCATE TABLE test.test;
 INSERT INTO test.test(timestamp) VALUES (UNIX_TIMESTAMP());
 END |
delimiter ;

Above scheduled event query will add two  job : ‘TRUNCATE TABLE’ and INSERT in mysql at specific time (2016-06-19 10:00:00).

You see?, Secret to Run Multiple query in a single Scheduled Event in MYSQL is by adding some parameter, it is : delimiter |, BEGIN setelah DO, END |, delimiter ;

 

Leave a Reply