你可以这样说:
CREATE TABLE `ttt` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`t1` TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00',
`t2` TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00',
`t3` TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00',
`t4` TIMESTAMP NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;
- 因为时间戳值存储为新纪元的秒数,时间戳值“1970-01-01 00:00:00”(UTC)被保留因为第二个#0用来表示'0000-00-00 00:00:00'。
- 在MariaDB 5.5和之前,每个表中只能有一个TIMESTAMP列,其CURRENT_TIMESTAMP被定义为其默认值。从MariaDB 10.0开始,此限制不再适用。
见:https://mariadb.com/kb/en/mariadb/timestamp/
样品
MariaDB []> insert into ttt (id) VALUES (1),(2),(3);
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
MariaDB []> select * from ttt;
+----+---------------------+---------------------+---------------------+---------------------+
| id | t1 | t2 | t3 | t4 |
+----+---------------------+---------------------+---------------------+---------------------+
| 1 | 0000-00-00 00:00:00 | 2000-01-01 12:01:02 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 2 | 0000-00-00 00:00:00 | 2000-01-01 12:01:02 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 3 | 0000-00-00 00:00:00 | 2000-01-01 12:01:02 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
+----+---------------------+---------------------+---------------------+---------------------+
3 rows in set (0.00 sec)
MariaDB []>
这些列的默认值是什么? 你可以请分享表结构吗? – Priyanshu
@Priyanshu我已经更新了我的表结构 – iamsujit
设置了最后两列的默认值current_timestamp。 – Priyanshu