Skip to content
Advertisement

How do I reset a MySQL column in a table every year?

I have a column named lv_casual in a table called tbl_employees. I need to reset the column to 0 at a specific date every year.

Advertisement

Answer

You can use MySQL event schedule. Providing an example below.

You have to enable the schedular first

SET GLOBAL event_scheduler = ON;

Then create the event

    CREATE EVENT your_event_name
    ON SCHEDULE EVERY 1 YEAR
    STARTS '2021-10-12 00:00:00'
    DO
    UPDATE table SET column=0;

Check MySQL document for creating event

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement