perkes456 perkes456 - 6 months ago 13
SQL Question

Reseting MySql column value each month

I was wondering if there is any way to reset a value in MySql each month. Like lets say I have a points column and its value for april was 500. When the new month kicks in, I'd like that the MySql (or whatever is needed) to reset that value back to 0, so that each new month that value is 0. What are possible ways to do this? I'm quite new with MySQL and PHP in general so I'm not really sure what to do here? Can someone help me out? Thanks heaps guys!

Best regards

Answer

You can use the MySQL event scheduler

delimiter //
CREATE EVENT your_event ON SCHEDULE 
       EVERY 1 MONTH
       STARTS '2016-05-01 00:00:00'
       ON COMPLETION PRESERVE ENABLE
    DO
      update your_table set ...;
//
Comments