Having Both Created and Last Updated Timestamp Columns in MySQL
The question concerns the feasibility of having both 'Created' and 'LastUpdated' TIMESTAMP columns in MySQL 4.0, which allows only one TIMESTAMP column with a CURRENT_TIMESTAMP default or ON UPDATE clause.
Solution:
As stated in the MySQL 5.5 documentation: "It is not possible to have the current timestamp be the default value for one column and the auto-update value for another column." Therefore, in MySQL 4.0, one cannot have both a 'Created' and 'LastUpdated' TIMESTAMP column with automatic updates.
However, in MySQL 5.6.5 and later, this restriction has been lifted. This means that any TIMESTAMP column can have a combination of DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP clauses. As a result, it is now possible to create both 'Created' and 'LastUpdated' TIMESTAMP columns with automatic updates.
The above is the detailed content of Can I Have Both Created and Last Updated Timestamp Columns in MySQL?. For more information, please follow other related articles on the PHP Chinese website!