本文章来给各位同学介绍关于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() |