ON UPDATE CURRENT_TIMESTAMP

CREATE TABLE time1 (
  id SMALLINT,
  time1 TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  time2 TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ;

INSERT INTO time1 VALUES(100,'',''),(101,NOW(),NOW());

SELECT * FROM time1;

id  time1                time2               
------  -------------------  ---------------------
   100  0000-00-00 00:00:00  0000-00-00 00:00:00 
   101  2015-03-30 10:02:18  2015-03-30 10:02:18

UPDATE time1 SET id=102;

SELECT * FROM time1;

id  time1                time2               
------  -------------------  ---------------------
   102 2015-03-30 10:03:10  0000-00-00 00:00:00 
   102  2015-03-30 10:03:10  2015-03-30 10:02:18

总结:

DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP  ---可以用于记录最后更新时间。

上一篇:Yacc 与 Lex 快速入门(词法分析和语法分析)


下一篇:多线程学习笔记六之并发工具类CountDownLatch和CyclicBarrier