MYSQL 更新时间自动同步与创建时间默认值共存问题
来源:互联网 发布:php项目开发流程 编辑:程序博客网 时间:2024/04/30 10:28
本文作者:苏生米沿
本文地址:http://blog.csdn.net/sushengmiyan/article/details/50326259
在使用SQL的时候,希望在更新数据的时候自动填充更新时间,那么在MySQL中是如何实现的呢?
如创建表users
其中,UPDATETIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NULL COMMENT '更新时间',会在更新的时候自动填充。啦啦啦。高兴吧。
不要高兴如此早,如果你使用的是mysql5.4版本,那么你表创建的时候都会报错,别说更新时间了,看:
ERROR 1293 (HY000): Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
出错鸟,创建表就失败了。
看5.5版本的时间戳文档:http://dev.mysql.com/doc/refman/5.5/en/timestamp-initialization.html
One
TIMESTAMP
column in a table can have the current timestamp as the default value for initializing the column, as the auto-update value, or both. It is not possible to have the current timestamp be the default value for one column and the auto-update value for another column.
可以看到这个版本对时间戳有限制。
再看5.7版本的
http://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html
已经没有这个限制了。我觉得,低版本的就只能另想办法,手动或者使用触发器来做更新时间这件事情啦。要么就直接升级版本解决问题。。
- MYSQL 更新时间自动同步与创建时间默认值共存问题
- MYSQL 更新时间自动同步与创建时间默认值共存问题
- mysql创建与更新时间字段
- VC自动与Internet时间服务器同步更新
- hibernate+mysql,注解方式,自动添加创建,更新时间
- Mybatis+Mysql插入时间默认值问题
- Android 时间同步与更新
- Android 时间 更新与同步
- MySQL--创建时间和更新时间字段
- 时间自动与域同步
- MySQL时间默认值
- mysql 设置时间 默认值
- mysql设置时间默认值
- MySQL服务器时间同步问题
- MySQL服务器时间同步问题
- mysql 创建表时 日期字段默认值为当前时间
- Android 2.3时间 更新与同步
- mysql timestamp 默认值当前时间
- struts2中使用json遇到的问题总结及示例程序
- SQL Server 通过JOB来定期获取数据库相关性能数据—JOB介绍
- linux 网络命名空间 Network namespaces
- AOP自定义校验功能模块
- linux中编写脚本(简单)
- MYSQL 更新时间自动同步与创建时间默认值共存问题
- nginx学习-开篇
- 【转载】-HDU 1007 hdu 1007 Quoit Design (最近点对)
- C++作业4
- java、js 获取视频时长
- CentOS7 安装JDK1.8
- 大量并发SQL导致数据库性能问题诊断优化
- ubuntu 16gcc g++版本降级
- CSS3 flex弹性布局