Home >Database >Mysql Tutorial >Can MySQL Tables Now Have Multiple CURRENT_TIMESTAMP Columns?
Multiple TIMESTAMP Columns with CURRENT_TIMESTAMP: A Historical Restriction
In previous versions of MySQL, a limitation restricted tables to having only one TIMESTAMP column automatically initialized or updated to the current date and time using the CURRENT_TIMESTAMP clause. This constraint extended to both DEFAULT and ON UPDATE clauses.
Relaxed Restriction in MySQL 5.6.5
MySQL version 5.6.5 brought a significant change, lifting the historical restriction. With this release, any TIMESTAMP column can have any combination of DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP clauses.
Example:
The following table definition, which previously raised an error, is now valid starting from MySQL 5.6.5:
CREATE TABLE `foo` ( `ProductID` INT(10) UNSIGNED NOT NULL, `AddedDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `UpdatedDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=INNODB;
Note: This change also applies to DATETIME column definitions, which now support the same clauses and combinations.
The above is the detailed content of Can MySQL Tables Now Have Multiple CURRENT_TIMESTAMP Columns?. For more information, please follow other related articles on the PHP Chinese website!