Power@IT的专栏

来自IT的力量 --- 从工作中升级知识,以激情来推进事业!

MySQL中,关于TIMESTAMP的初始化相关摘录

摘自Automatic Initialization and Updating for TIMESTAMP

  • 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
    );

  • 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
    );

  • 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.

  • 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
    );

  • 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
    );

  • 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
    );

  • 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 CURRENT
    TIMESTAMP -- default NULL
    );

阅读更多
文章标签: timestamp mysql
想对作者说点什么? 我来说一句

mysql TIMESTAMP详解

摘要

lapiggy lapiggy

2010-08-23 16:23:00

阅读数:21093

没有更多推荐了,返回首页

不良信息举报

MySQL中,关于TIMESTAMP的初始化相关摘录

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭