CREATE TABLE `ts` (                                                               
          `ts1` timestamp NOT NULL ,
          `ts2` timestamp NOT NULL default CURRENT_TIMESTAMP,
    `ts3` timestamp NULL default NULL                           
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8

错误码: 1293
Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

Execution Time : 00:00:00:000
Transfer Time : 00:00:00:000
Total Time     : 00:00:00:000

创建的时候ts1 跟ts2 是一样的,只能有一个更新的时候更新



CREATE TABLE `ts` (                                                               
        
      `ts2` timestamp NOT NULL default CURRENT_TIMESTAMP,
    `ts3` timestamp NULL default NULL                           
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8
这样子更新后的ts2不会自动更新


CREATE TABLE `ts` (                                                               
      `ts1` timestamp NOT NULL ,      
    `ts3` timestamp NULL default NULL                           
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8
插入之后SQL语句变成了
CREATE TABLE `ts` (                                                               
          `ts1` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
          `ts3` timestamp NULL default NULL                                               
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8      

   `ts1` timestamp NOT NULL , => `ts1` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
                                       
这时更新的时候就会自动更新ts1字段了,不想要更新就创建的时候加各default
`ts2` timestamp NOT NULL default CURRENT_TIMESTAMP,

默认为空是 `ts3` timestamp NULL default NULL        而不是 `ts3` timestamp default NULL     
posted on 2009-06-11 18:02  葛森  阅读(1368)  评论(0编辑  收藏  举报