I have set 1 mysql events that transferring all data with 0
flag from one table to another (table 2) every 12 hours, then update query to set as 1
the flag after transferring. INSERT
and UPDATE
is on one event process.
My problem is, all transferred data have duplicate on the table 2 that looks like 2 event is running.
Any idea?
Here is my event codes:
DELIMITER |
CREATE
EVENT
IF NOT EXISTS
event_transfer
ON SCHEDULE EVERY 12 HOUR
STARTS '2018-08-10 06:00:00'
ON COMPLETION NOT PRESERVE
ENABLE
DO
BEGIN
INSERT INTO dbsample.tblmirror (Column1, Column2, Column3)
(SELECT Column1, Column2, Column3
FROM tblmaster
WHERE is_transfer = 0);
UPDATE dbsample.tblmaster
SET is_transfer = 1
WHERE is_transfer = 0;
END |
DELIMITER;