• mysql 5.5与5.6 timestamp 字段 DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP的区别


    http://www.111cn.net/database/mysql/55392.htm

    本文章来给各位同学介绍关于mysql 5.5与5.6 timestamp 字段 DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP的区别,希望此教程对各位有帮助。
     

    mysql5.6数据库:

     代码如下 复制代码
    [BIGHD](root@127.0.0.1) [cm]> SELECT version();
    +------------+
    | version()  |
    +------------+
    | 5.6.13-log |
    +------------+
    1 ROW IN SET (0.02 sec)
     
    [BIGHD](root@127.0.0.1) [cm]> ALTER TABLE s__uk ADD `last_op_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
    Query OK, 0 ROWS affected (0.99 sec)
    Records: 0  Duplicates: 0  Warnings: 0
     
    [BIGHD](root@127.0.0.1) [cm]> SELECT id, last_op_time FROM s__uk  LIMIT 1;
    +----+---------------------+
    | id | last_op_time        |
    +----+---------------------+
    |  1 | 2013-10-10 10:17:57 |
    +----+---------------------+
    1 ROW IN SET (0.00 sec)
     


     
     
    mysql5.5数据库:

     代码如下 复制代码

    (root@localhost) [cm]> SELECT version();
    +------------+
    | version()  |
    +------------+
    | 5.5.15-log |
    +------------+
    1 ROW IN SET (0.00 sec)
     
    (root@localhost) [cm]> ALTER TABLE s__uk ADD `last_op_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
    Query OK, 2523 ROWS affected (0.99 sec)
    Records: 2523  Duplicates: 0  Warnings: 0
     
    (root@localhost) [cm]> SELECT last_op_time FROM s__uk  LIMIT 1;
    +---------------------+
    | last_op_time        |
    +---------------------+
    | 0000-00-00 00:00:00 |
    +---------------------+
    1 ROW IN SET (0.00 sec)

    另外,有没有考虑过如果只更新这个字段会怎样?会是指定的时间,还是自动生成的时间?

     代码如下 复制代码
    (root@localhost) [cm]> UPDATE s__uk SET last_op_time='2012-12-12 00:00:00' WHERE id=1;
    Query OK, 1 ROW affected (0.07 sec)
    ROWS matched: 1  Changed: 1  Warnings: 0
     
    (root@localhost) [cm]> SELECT id, last_op_time FROM s__uk  LIMIT 1;
    +----+---------------------+
    | id | last_op_time        |
    +----+---------------------+
    |  1 | 2012-12-12 00:00:00 |
    +----+---------------------+
    1 ROW IN SET (0.01 sec)

    猜对了木有?

    PS:
    如何判断字段中是否有多字节字符(比如中文)?

    CHARACTER_LENGTH(value) = length(value) 则不包含多字节字符。

    length为字节Bytes长度, CHARACTER_LENGTH为字符characters长度。

    PS2:
    mongodb find()

    之后美化/格式化输出的函数是:
    db.tbl.find().pretty()

    ​http://www.111cn.net/database/mysql/55392.htm

  • 相关阅读:
    查询避免Unknown column ‘xxx’ in ‘where clause
    Spring依赖循环:The dependencies of some of the beans in the application context form a cycle
    POJ(北京大学)刷题导航
    ACM使用Java提交总是超时的解决方法
    申请了服务器,建立了新博客。 不在用这个了。
    jeecg数据库添加字段后表单的修改
    jeecg普通表和数据字典的关联
    jeecg添加滚动图
    jeecg定时任务的bug记录
    classpath究竟是指哪里?
  • 原文地址:https://www.cnblogs.com/seasonzone/p/3842660.html
Copyright © 2020-2023  润新知