Why there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT clause?(为什么在 DEFAULT 子句中只能有一个带有 CURRENT_TIMESTAMP 的 TIMESTAMP 列?)
问题描述
为什么在 DEFAULT 或 ON UPDATE 子句中只能有一个带有 CURRENT_TIMESTAMP 的 TIMESTAMP 列?
Why there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause?
CREATE TABLE `foo` (
`ProductID` INT(10) UNSIGNED NOT NULL,
`AddedDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`UpdatedDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=INNODB;
导致的错误:
错误代码:1293
表定义不正确;有可以只有一个 TIMESTAMP 列DEFAULT 或 ON 中的 CURRENT_TIMESTAMP更新子句
Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
推荐答案
这个限制,这只是由于历史的,代码遗留的原因,在最近的 MySQL 版本中被取消了:
This limitation, which was only due to historical, code legacy reasons, has been lifted in recent versions of MySQL:
MySQL 5.6.5 的变化(2012-04-10,里程碑 8)
Changes in MySQL 5.6.5 (2012-04-10, Milestone 8)
以前,每个表最多可以有一个 TIMESTAMP 列自动初始化或更新为当前日期和时间.此限制已取消.任何 TIMESTAMP 列定义都可以具有 DEFAULT CURRENT_TIMESTAMP 和 ON UPDATE 的任意组合CURRENT_TIMESTAMP 子句.此外,现在可以使用这些子句带有 DATETIME 列定义.有关更多信息,请参阅自动TIMESTAMP 和 DATETIME 的初始化和更新.
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.
http://dev.mysql.com/doc/relnotes/mysql/5.6/en/news-5-6-5.html
这篇关于为什么在 DEFAULT 子句中只能有一个带有 CURRENT_TIMESTAMP 的 TIMESTAMP 列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么在 DEFAULT 子句中只能有一个带有 CURRENT_TIMESTAMP 的 TIMESTAMP 列?


- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- SQL 临时表问题 2022-01-01