为什么在DEFAULT子句中只能有一个带有CURRENT_TIMESTAMP的TIMESTAMP列? [英] Why there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT clause?

查看:527
本文介绍了为什么在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

Error Code : 1293

错误的表定义;可以 只能是一个TIMESTAMP列, CURRENT_TIMESTAMP为DEFAULT或ON UPDATE子句

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列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆