Having Both Created and Last Updated Timestamp Columns in MySQL
In MySQL 4.0, it was not possible to specify both Created and LastUpdated columns as TIMESTAMPs with the CURRENT_TIMESTAMP default or on update clause. The error encountered when attempting to create such a table reflects this limitation.
Upon upgrading to MySQL 5.5, there was still a restriction on having only one TIMESTAMP column with the CURRENT_TIMESTAMP in either the default or on update clause. Manual updates were required for the LastUpdated field.
However, a significant change occurred in MySQL 5.6.5. The restriction on TIMESTAMP columns was lifted, allowing for multiple columns to be automatically initialized or updated to the current date and time. This includes DATETIME columns as well.
Therefore, in MySQL versions 5.6.5 and later, it is possible to have both Created and LastUpdated columns as TIMESTAMPs with the CURRENT_TIMESTAMP default or on update clause. These clauses can be used with any combination, providing greater flexibility in tracking record creation and updates.
The above is the detailed content of Can MySQL Timestamp Columns Be Both Created and Last Updated?. For more information, please follow other related articles on the PHP Chinese website!