DelphiFAQ Home Search:
General :: Databases :: mysql
General information about mysql - how to get around the differences between version 3.33 an 4, how to do stuff that you think you need a nested query for etc.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

My timestamp field in mysql does not update

Question:

To track changes in our database, I added two columns to all my tables named

LAST_CHANGE TIMESTAMP
LAST_USER VARCHAR(48)

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.

Explanation:

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.


Generated 8:00:45 on Oct 21, 2018