Ad

Moving MySQL Record To Other Table After Timeframe

- 1 answer

I am trying to find the best way to process a record with a timestamp field whereby it would automatically move from one table to another table after 30 minutes.

Ad

Answer

If you are using MySQL 5.1.6 and later, check out MySQL events.

Events work the same with other routines, you can CREATE, ALTER, and even DROP them.

Martin Psinas has basic examples of this. (Just found online, we're not friends, lol)

First, you'll have to enable events scheduler:

SET GLOBAL event_scheduler = ON;

Then, you can create your event like (base from your question):

CREATE EVENT ProcessRecord
    ON SCHEDULE EVERY 30 MINUTE
    --STARTS CURRENT_TIMESTAMP + INTERVAL 1 DAY
    --ENDS CURRENT_TIMESTAMP + INTERVAL 1 YEAR
    DO
      BEGIN
        INSERT INTO ...
            SELECT ...
      END

Otherwise, you can go with windows scheduled tasks, if you're using windows platform.

Ad
source: stackoverflow.com
Ad