Nov 1, 2018

How to Automatic Initialization and Updating for TIMESTAMP and DATETIME in MySQL

Automatic Initialization and Updating for TIMESTAMP and DATETIME in MySQL


Example:

CREATE TABLE t1 (
  ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  dt DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);