MySql表有两个或更多列有默认日期vaule CURRENT_TIMESTAMP,任何解决方案?

时间:2023-02-03 12:21:39

if i have a table with two columns create_time and update_time,the data type is timestamp,then have default value CURRENT_TIMESTAMP,the sql code of created table is:

如果我有一个包含两列create_time和update_time的表,则数据类型为timestamp,然后具有默认值CURRENT_TIMESTAMP,创建的表的sql代码为:

CREATE TABLE `t_activity` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `STARTDATE` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `ENDDATE` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`ID`)
);

but it prompt
error:1293,there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or UPDATE clause.

但它提示错误:1293,在DEFAULT或UPDATE子句中只能有一个TIMESTAMP列和CURRENT_TIMESTAMP。

2 个解决方案

#1


0  

I am not sure what you're trying to accomplish having both the STARTDATE and ENDDATE populated with the CURRENT_TIMESTAMP. However to fix your code try changing your data types to DATETIME like this:

我不确定你要用STARTRATE和ENDDATE填充CURRENT_TIMESTAMP来完成什么。但是要修复代码,请尝试将数据类型更改为DATETIME,如下所示:

**CREATE TABLE `t_activity` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `STARTDATE` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `ENDDATE` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`ID`)
);**

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

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

#2


0  

This limitation in Mysql:

Mysql中的这个限制:

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.

以前,每个表最多只能有一个TIMESTAMP列自动初始化或更新到当前日期和时间。这一限制已被取消。任何TIMESTAMP列定义都可以包含DEFAULT CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIMESTAMP子句的任意组合。此外,这些子句现在可以与DATETIME列定义一起使用。有关更多信息,请参阅TIMESTAMP和DATETIME的自动初始化和更新。

Check This for more detail

选中此处了解更多详情

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

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

#1


0  

I am not sure what you're trying to accomplish having both the STARTDATE and ENDDATE populated with the CURRENT_TIMESTAMP. However to fix your code try changing your data types to DATETIME like this:

我不确定你要用STARTRATE和ENDDATE填充CURRENT_TIMESTAMP来完成什么。但是要修复代码,请尝试将数据类型更改为DATETIME,如下所示:

**CREATE TABLE `t_activity` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `STARTDATE` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `ENDDATE` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`ID`)
);**

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

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

#2


0  

This limitation in Mysql:

Mysql中的这个限制:

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.

以前,每个表最多只能有一个TIMESTAMP列自动初始化或更新到当前日期和时间。这一限制已被取消。任何TIMESTAMP列定义都可以包含DEFAULT CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIMESTAMP子句的任意组合。此外,这些子句现在可以与DATETIME列定义一起使用。有关更多信息,请参阅TIMESTAMP和DATETIME的自动初始化和更新。

Check This for more detail

选中此处了解更多详情

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

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