网站地图    收藏   

主页 > 后端 > PHP语言 >

mysql 5.5与5.6 timestamp 字段 DEFAULT CURRENT_TIMESTAMP ON

来源:自学PHP网    时间:2014-12-04 21:50 作者: 阅读:

[导读] mysql 5.5与5.6 timestamp 字段 DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP的区别. 5.6: [BIGHD](root@127.0.0.1) [cm] SELECT version(); +------------+ | version() | +------------+ | 5.6.13-log | +------------+ 1 ROW IN SET (0.02...

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


5.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)



5.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()
 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论