Bug #4330 TIMESTAMP field inadvertently updating on UPDATE
Submitted: 29 Jun 2004 18:56 Modified: 29 Jun 2004 19:04
Reporter: Christopher Bartling Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.0.18 OS:Windows (Windows 2000 Server)
Assigned to: Dean Ellis CPU Architecture:Any

[29 Jun 2004 18:56] Christopher Bartling
Description:
Given a table with two or more TIMESTAMP fields, any SQL UPDATE of a row in the table will always update the row's first TIMESTAMP field, even though none of the TIMESTAMP columns are participating in the SET clause of the UPDATE statement.  The updated TIMESTAMP column value is set to the current date and time.  The second and subsequent TIMESTAMP fields are unaffected by the update, but the first field is always updated.

How to repeat:
Given the following table schema:

CREATE TABLE timestamp_example (
	id                          BIGINT NOT NULL AUTO_INCREMENT,
	timestamp1                  TIMESTAMP       NULL DEFAULT 00000000000000,
	timestamp2                  TIMESTAMP       NULL DEFAULT 00000000000000,
	timestamp3                  TIMESTAMP       NULL DEFAULT 00000000000000,
	update_value                int             NOT NULL,

	PRIMARY KEY (id)
);

Please note that I observed, through the use of DbVisualizer 4.1, that the COLUMN_DEF is different between timestamp1 field and the timestamp2 and timestamp3 fields.  The COLUMN_DEF is null for the timestamp1 field, but set to '00000000000000' for the other two fields.  Seems strange, since they're all defined the same.   

Now insert one row into the table, setting all the timestamps to the current date and time:

INSERT INTO timestamp_example (timestamp1, timestamp2, timestamp3, update_value)
VALUES (NOW(), NOW(), NOW(), 1);

Now update the update_value in that single row in the table: 

UPDATE timestamp_example SET update_value = 2 

Observe the timestamp fields now.  The first timestamp field's value has changed, even though you did not explicitly set it in the UPDATE statement.
[29 Jun 2004 19:04] Dean Ellis
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

Additional info:

http://dev.mysql.com/doc/mysql/en/TIMESTAMP_pre-4.1.html