Home > Database > Mysql Tutorial > Can a MySQL 4.0 Table Have Both Created and LastUpdated Timestamp Columns?

Can a MySQL 4.0 Table Have Both Created and LastUpdated Timestamp Columns?

Barbara Streisand
Release: 2024-11-13 10:38:02
Original
812 people have browsed it

Can a MySQL 4.0 Table Have Both Created and LastUpdated Timestamp Columns?

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,
  ...
);
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template