Jin Kwon Asked: 2016-07-15 20:49:08 +0800 CST2016-07-15 20:49:08 +0800 CST 2016-07-15 20:49:08 +0800 CST 如何将 TIMESTAMP 的默认值设置为未来日期? 772 我知道我可以像这样使用当前时间戳设置默认值 ... DEFAULT CURRENT_TIMESTAMP 有没有办法根据当前时间戳设置具有固定数量单位的列? ... DEFAULT CURRENT_TIMESTAMP + 10 days? mysql timestamp 1 个回答 Voted Best Answer Philᵀᴹ 2016-07-16T06:26:37+08:002016-07-16T06:26:37+08:00 使用触发器: mysql> CREATE TRIGGER dateinsert BEFORE INSERT ON testtable -> FOR EACH ROW -> SET NEW.yourdate = DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL 10 DAY); Query OK, 0 rows affected (0.00 sec) mysql> insert into testtable (blah) values (1); Query OK, 1 row affected (0.00 sec) mysql> select * from testtable; +------+------------+ | blah | yourdate | +------+------------+ | 1 | 2016-07-25 | +------+------------+ 1 row in set (0.00 sec) mysql>
使用触发器: