MySQL下,如何同时使用两个timestamp类型的字段?
伊谢尔伦
伊谢尔伦 2017-04-17 11:25:25
[MySQL讨论组]

现在:
ctime记录创建的时间戳, defaul null
utime记录更新的时间戳, default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

使用的插入语句
insert on duplicate key update
它会同时修改ctime和utime

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(1)
黄舟

我想你说的是这个:

mysql 5.6.4 doc:
http://dev.mysql.com/doc/relnotes/mysql/5.6/en/news-5-6-5.html

Previously, at most one TIMESTAMP column per table could be automatically initialized or updated to the current date and time.
This restriction has been lifted. Any TIMESTAMP column definition can
have any combination of DEFAULT CURRENT_TIMESTAMP and ON UPDATE
CURRENT_TIMESTAMP clauses. In addition, these clauses now can be used
with DATETIME column definitions. For more information, see Automatic
Initialization and Updating for TIMESTAMP and DATETIME.

这是一个mysql 5.6.4之前的limitation. 我在5.5.24上试了,

mysql> create table mytime (id int, ctime timestamp default current_timestamp, u
time timestamp default current_timestamp on update current_timestamp);

会报:

RROR 1293 (HY000): Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

5.6.12上没有问题.

如果想在mysql 5.6.4之前用这个功能, 自己去弄一个trigger吧.

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号