Having a Created and Last Updated Timestamp in MySQL 4.0
Question:
Can a table in MySQL 4.0 have both a Created and a LastUpdated timestamp column? Or must the LastUpdated field be manually set during each transaction?
Answer:
In MySQL versions 4.0-5.6.4, only one TIMESTAMP column per table could be automatically updated to the current date and time, either as a default value or as an auto-update value. This meant that you could not have both a Created and a LastUpdated timestamp column with these automatic updates.
However, with the release of MySQL 5.6.5, this restriction was lifted. Any TIMESTAMP column can now have any combination of DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP clauses.
Therefore, in MySQL versions 5.6.5 and later, it is possible to have both a Created and a LastUpdated timestamp column with the following schema:
CREATE TABLE `db1`.`sms_queue` ( ... `Created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `LastUpdated` TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP, ... );
The above is the detailed content of Can a MySQL 4.0 Table Have Both Created and LastUpdated Timestamp Columns?. For more information, please follow other related articles on the PHP Chinese website!