Chinaunix

标题: mysql timestamp使用说明 [打印本页]

作者: sss0213    时间: 2009-07-01 09:28
标题: mysql timestamp使用说明

mysql官方文档:
http://dev.mysql.com/doc/refman/5.1/en/timestamp.html
,说了一大堆timestamp的用法,我觉得最后总结的特别好,给它翻译过来:

ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP

ts TIMESTAMP DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP

ts TIMESTAMP DEFAULT 0
但是需要注意的是:mysql中一个表里,不能有两个字段同时是DEFAULT CURRENT_TIMESTAMP,即使一个是默认当前时间,另一个是默认当前时间+更新更新,例如:
CREATE TABLE `t1` (
  `id` int(11) NOT NULL auto_increment,
  `ts1` timestamp NOT NULL default '0000-00-00 00:00:00',
  `ts2` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP                  ,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM
mysql> alter table t1 modify ts1 timestamp NOT NULL default CURRENT_TIMESTAMP;
ERROR 1293 (HY000): Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/50685/showart_1982419.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2