• 1
  • 2
  • 3
  • 4
  • 5
mysql數據庫問題 首 頁  ?  幫助中心  »  數據庫  »  mysql數據庫問題
關于MySQL中TIMESTAMP的初始化相關摘錄
發布日期:2016-4-30 17:4:50

  本文摘自《Automatic Initialization and Updating for TIMESTAMP》

  (1)With both DEFAULT CURRENTTIMESTAMP and ON UPDATE CURRENTTIMESTAMP, the column has the current timestamp for its default value and is automatically updated to the current timestamp.

  CREATE TABLE t1 (

  ts TIMESTAMP DEFAULT CURRENTTIMESTAMP ON UPDATE CURRENTTIMESTAMP

  );

  (2)With neither DEFAULT CURRENTTIMESTAMP nor ON UPDATE CURRENTTIMESTAMP, it is the same as specifying both DEFAULT CURRENTTIMESTAMP and ON UPDATE CURRENTTIMESTAMP.

  CREATE TABLE t1 (

  ts TIMESTAMP

  );

  (3)With a DEFAULT clause but no ON UPDATE CURRENT_TIMESTAMP clause, the column has the given default value and is not automatically updated to the current timestamp.

  (4)The default depends on whether the DEFAULT clause specifies CURRENTTIMESTAMP or a constant value. With CURRENTTIMESTAMP, the default is the current timestamp.

  CREATE TABLE t1 (

  ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP

  );

  (5)With a constant, the default is the given value. In this case, the column has no automatic properties at all.

  CREATE TABLE t1 (

  ts TIMESTAMP DEFAULT 0

  );

  (6)With an ON UPDATE CURRENT_TIMESTAMP clause and a constant DEFAULT clause, the column is automatically updated to the current timestamp and has the given constant default value.

  CREATE TABLE t1 (

  ts TIMESTAMP DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP

  );

  (7)With an ON UPDATE CURRENT_TIMESTAMP clause but no DEFAULT clause, the column is automatically updated to the current timestamp. The default is 0 unless the column is defined with the NULL attribute, in which case the default is NULL.

  CREATE TABLE t1 (

  ts TIMESTAMP ON UPDATE CURRENTTIMESTAMP -- default 0

  );

  CREATE TABLE t2 (

  ts TIMESTAMP NULL ON UPDATE CURRENTTIMESTAMP -- default NULL

  );

  以后會更新更多mysql的相關文章,敬請期待。

什么行业的讲师最赚钱 德甲和意甲哪个厉害 腾讯欢乐捕鱼大战官网 麻将来了旧版本官网 意甲历史总积分榜 云南飞小鸡麻将 股票k线图片 35选7历史开奖号码查询 贵州茅台股票代码是 三分彩-首页 幸运赛车选号技巧