Skip to content Skip to sidebar Skip to footer

Update Column Value After Insert And Period Of Time

I have a table including status that default value is 0 when it inserted in the first time, I want to change this value from 0 to 1 after this row inserted in 24 hours, that means

Solution 1:

This is probably not the right approach. I mean, you could set up an event that gets processed for every row, but that could add a lot of load to your database.

Instead, if status is merely saying that the row is less or more than one day old, put a creation date into the table and use a view:

createview v_table asselect t.*, (creation_date >= date_sub(now(), interval1day) as status
     fromtable t;

If status can be changed by other means, then call it something like _status and do:

createview v_table asselect t.*,
            (casewhen creation_date >= date_sub(now(), interval1daythen1else _status end) as status
     fromtable t;

Post a Comment for "Update Column Value After Insert And Period Of Time"