0

I have a column in my MySQL database that uses a "TIMESTAMP" to capture the current time. I have an attribute set to "on update CURRENT_TIMESTAMP" so it auto updates the column whenever and update change is made.

Works great, except I have a small issue. My database also tracks views/votes for each row so basically the TIMESTAMP column is always being update because of the views/votes being updated. This isn't exactly what I want as I only want the TIMESTAMP column to update when significant information is changed that is not views/votes.

Is there a way to make phpmyadmin force this column to update when I make a manual edit on a row using the phpmyadmin edit gui? Besides having to type in the current TIMESTAMP which is just too time consuming for me.

Thanks!

1
  • The simplest way which I see is to use trigger logic instead of autoupdate (in BEFORE trigger, and remove autoupdate) or in addition to autoupdate (in AFTER trigger, and restore old value if needed).
    – Akina
    Commented Dec 7, 2018 at 9:42

1 Answer 1

1

The defaults for TIMESTAMP are quite limited. Instead of depending on it, take charge. You should supply values when you need them:

UPDATE tbl  SET
        ...,
        ts = NOW()   -- Include this when you need it; else leave it out.
    WHERE ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.