DELIMITER |
CREATE EVENT myevent
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 MINUTE
DO
BEGIN
DELETE FROM vehicle WHERE last_updated < (NOW() - INTERVAL 5 MINUTE)
END |
DELIMITER ;
Above I have a MySQL event that runs every minute deleting rows that haven't been updated for 5 minutes. I have another table called saved_vehicles. All of the rows in vehicle
will have a row in the saved_vehicle
table. What I want to do is essentially copy over the last_updated
time to the saved_vehicle
table (for example purposes, imagine the saved_vehicle
field would be last_known_online_time
. This essentially saves a copy of the vehicle with its last known online time.
Essentially I'm creating a backup before deleting the row.