[MySQL] Changing TIMESTAMP behaviour

Associate
Joined
21 May 2003
Posts
1,365
I have a timestamp field for which the default value is currently set to "CURRENT_TIMESTAMP", yet the field is automatically updated whenever the row is modified. I thought this behaviour was when "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP" was specified.

I want to change this to only being set on INSERT, and then left as it is. I know I could get around this by setting the field to datetime and updating via my code, but surely there is a quick fix?

MySQL version is 4.1.7. - the docs say that the feature was added in 4.1.2:

Added support for DEFAULT CURRENT_TIMESTAMP and for ON UPDATE CURRENT_TIMESTAMP specifications for TIMESTAMP columns. Now you can explicitly say that a TIMESTAMP column should be set automatically to the current timestamp for INSERT and/or UPDATE statements, or even prevent the column from updating automatically. Only one column with such an auto-set feature per table is supported. TIMESTAMP columns created with earlier versions of MySQL behave as before. Behavior of TIMESTAMP columns that were created without explicit specification of default/on as earlier depends on its position in table: If it is the first TIMESTAMP column, it be treated as having been specified as TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP. In other cases, it would be treated as a TIMESTAMP DEFAULT 0 column. NOW is supported as an alias for CURRENT_TIMESTAMP. Warning: Incompatible change: Unlike in previous versions, explicit specification of default values for TIMESTAMP column is never ignored and turns off the auto-set feature (unless you have CURRENT_TIMESTAMP as the default).

However i'm pretty sure this server has undergone various upgrades, so the table may well have been created in a version prior to 4.1.2 and is keeping the behaviour as before.

Any ideas (would re-creating the table and copying in the data work)?
 
Back
Top Bottom