Resetting Column Values ββAfter Time
1 answer
What you want is called an "event". Here's a potential definition; your needs may vary.
CREATE EVENT `zero_my_column`
ON SCHEDULE
EVERY 72 HOUR STARTS '2015-07-13 00:00:00'
ON COMPLETION PRESERVE
ENABLE
DO BEGIN
UPDATE mytable SET counter = 0 WHERE counter <> 0;
END
This is where some configuration tweak is done to ensure your MySQL server is properly handling this event.
This is the actual update request.
UPDATE mytable SET counter = 0 WHERE counter <> 0;
Pay attention to the offer WHERE
. This prevents redundant updating of rows that already have a null column value forcounter.
+2
source to share