Issue
I'm creating a public messaging service and I was wondering, in order to perform a cleanse of the oldest messages, is it okay to delete the oldest message every time a new one is submitted? Or is this approach inefficient for some reason? If so, could you specify why?
I considered create a Cron Job for this, but I'm not sure if it applies in this case.
Solution
You can schedule an event in MySQL:
DELIMITER $$
CREATE EVENT cleanup_messages ON SCHEDULE EVERY day ENABLE
DO BEGIN
DELETE FROM messages WHERE ......;
END $$
DELIMITER ;
http://dev.mysql.com/doc/refman/5.1/en/create-event.html
Answered By - Johan Answer Checked By - Willingham (WPSolving Volunteer)