Needed: mysql current timestamp on update also if UPDATE does not change values in table

mysql, timestamp

Solution

In your query, just always update the `last_updated` field using `NOW()`. Like this:

UPDATE table SET price = ?, last_updated = NOW() WHERE id = ??

Problem

I have a database with 3 columns: ID / Price / last_updated The column "last_updated" has .. - as type: timestamp - as Standard: CURRENT_TIMESTAMP - as Attribute: CURRENT TIMESTAMP ON UPDATE - as Extra : CURRENT TIMESTAMP ON UPDATE when I run a mysql_query(UPDATE...) to change the prices, some prices do not change. In those cases, however, the last_updated value remains the same than before (which in this case is: 0000-00-00 00:00:00 as the records have not been changed). So I guess, UPDATE only "updates" if the new value is different from the current one in place. How can I get the current timestamp put into the table, even if the value is not changed after performing a mysql_query(UPDATE...) ?

Original source