MySQL `explicit_defaults_for_timestamp` 与 TIMESTAMP
Posted wayou
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL `explicit_defaults_for_timestamp` 与 TIMESTAMP相关的知识,希望对你有一定的参考价值。
考察下面的 SQL 脚本: CREATE TABLE test1(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
data VARCHAR(20),
ts1 TIMESTAMP NOT NULL,
createdAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
); 语义上来看,这里 实际情况则不然,在 mysql> describe test1;
+-----------+-------------+------+-----+-------------------+-----------------------------------------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+-------------------+-----------------------------------------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| data | varchar(20) | YES | | NULL | |
| ts1 | timestamp | NO | | CURRENT_TIMESTAMP | DEFAULT_GENERATED on update CURRENT_TIMESTAMP |
| createdAt | timestamp | NO | | CURRENT_TIMESTAMP | DEFAULT_GENERATED |
| updatedAt | timestamp | NO | | CURRENT_TIMESTAMP | DEFAULT_GENERATED on update CURRENT_TIMESTAMP |
+-----------+-------------+------+-----+-------------------+-----------------------------------------------+
5 rows in set (0.01 sec)
|
以上是关于MySQL `explicit_defaults_for_timestamp` 与 TIMESTAMP的主要内容,如果未能解决你的问题,请参考以下文章