- 论坛徽章:
- 0
|
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
- 都不做(要是用这个的话,个人推荐用DATETIME日期类型):
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 |
|