你可以這樣說:
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