My timestamp field in mysql does not update
This article has not been rated yet. After reading, feel free to leave comments and rate it.
Question:To track changes in our database, I added two columns to all my tables named
The timestamp field should get updated every time any other column gets updated. For some tables this works, for some it does not. Why is that?
Answer:This behavior sounds like you are using a mysql version prior to 4.1.2. And in those tables where it does not work, you probably have another field of type TIMESTAMP already.
In mysql with versions before 4.1.2 the first TIMESTAMP column in automatically is set to the current timestamp when the record is created if the field value is set to NULL or not not specified at all. During updates the first TIMESTAMP column in table row automatically is updated to the current timestamp when the value of any other column in the row is changed, unless the TIMESTAMP column explicitly is assigned a value other than NULL.