MySQL CURRENT_TIMESTAMP on create and on update(MySQL CURRENT_TIMESTAMP 在创建和更新时)
问题描述
我想定义有 2 个 TIMESTAMP 字段的表,如下所示:
I want to define table which will have 2 TIMESTAMP fields, someting like this:
CREATE TABLE `msgs` (
`id` INT PRIMARY KEY AUTO_INCREMENT,
`msg` VARCHAR(256),
`ts_create` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`ts_update` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)
如何避免错误:
ERROR 1293 (HY000): Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
重点是在表模式中保持 ts_create
和 ts_update
的期望行为.
Point is to keep desired behavior of ts_create
and ts_update
in table schema.
推荐答案
猜这是一篇老帖子,但实际上我猜 mysql 在其最近的版本中支持 2 TIMESTAMP mysql 5.6.25 这就是我现在使用的.
Guess this is a old post but actually i guess mysql supports 2 TIMESTAMP in its recent editions mysql 5.6.25 thats what im using as of now.
这篇关于MySQL CURRENT_TIMESTAMP 在创建和更新时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL CURRENT_TIMESTAMP 在创建和更新时


基础教程推荐
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01