there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

建表语句:

create table test_table(
  id integer not null auto_increment primary key,
  stamp_created timestamp default ‘0000-00-00 00:00:00‘,
  stamp_updated timestamp default now() on update now()
);

测试:

 mysql> insert into test_table(stamp_created, stamp_updated) values(null, null); Query OK, 1 row affected (0.06 sec)

mysql> select * from t5; +----+---------------------+---------------------+ | id | stamp_created       | stamp_updated       |+----+---------------------+---------------------+|  2 | 2009-04-30 09:44:35 | 2009-04-30 09:44:35 |+----+---------------------+---------------------+2 rows in set (0.00 sec)  

mysql> update test_table set id = 3 where id = 2; Query OK, 1 row affected (0.05 sec) Rows matched: 1  Changed: 1  Warnings: 0
mysql> select * from test_table;+----+---------------------+---------------------+| id | stamp_created       | stamp_updated       | +----+---------------------+---------------------+ |  3 | 2009-04-30 09:44:35 | 2009-04-30 09:46:59 | +----+---------------------+---------------------+ 2 rows in set (0.00 sec)

参考这里:

http://stackoverflow.com/questions/267658/having-both-a-created-and-last-updated-timestamp-columns-in-mysql-4-0

时间: 2024-12-13 19:45:09

there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause的相关文章

Mysql [Err] 1293 there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

问题: mysql数据 导入数据出错 [Err] 1293 - Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause 原因: 数据库版本问题,mysql5.6及以上才支持,必须升级数据库版本.

Mysql运行SQL文件 错误Incorrect table definition;there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

问题描述 想从服务器上DOWN下数据库.操作:先把数据库转存为SQL文件,然后在本地利用navicate运行SQL文件,出现错误信息: Incorrect table definition;there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause 解决思路 参考: http://www.cnblogs.com/joeylee/p/3877578.html 原因:TIME

msyql同步的时候报错 : 错误代码: 1293 Incorrect table definition;there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

场景,两个不同服务器上的数据库,进行数据库同步 但是执行之后,提示报错 错误代码: 1293 Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause 原因: 两台服务器的mysql版本不一致. 低版本不支持在一个表里面 有2个TIMESTAMP 类型  的列. 我们使用 SELECT VERSION();  来查

mysql 多个timestamp 错误:there can be only one TIMESTAMP column with CURRENT_TIMESTAMP

mysql 5.6.5以下的版本不支持多个timestamp同时设为default current_timestamp 替代方式是使用trigger CREATE TABLE `example` ( `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `lastUpdated` DATETIME NOT NULL, PRIMARY KEY (`

mysql中单表多timestamp设置default问题

mysql中,同一个表多个timesatmp字段设置default的时候,经常会报错. 一个表只能有一个设置default的字段. 但是有时只有一个字段设置default也会报错. 会报:Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause 但是检查代码,发现只有一个timestamp设置了default. C

mysql数据导入遇到的timestamp类型问题

今天准备把最新的表导入自己以前的机子上做临时开发,在数据库导入的时候遇到一个问题:Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause 更具导入的日志提示是:表的错误定义:在一个表中只能有一个列指定为TIMESTAMP类型的列,并且使用CURRENT_TIMESTAMP 作为默认值或者是使用 ON UPDATE

【MySQL】探究之TIMESTAMP

背景 之前有业务反馈表中start_time,end_time时间字段随着时间的推移被自动更新,这可不是业务意愿,说的严重点是要出故障的. MySQL中有DATE,DATETIME,TIMESTAMP时间类型 看看官方文档怎么说 The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. Th

MySQL的timestamp类型自动更新问题【转】

今天建了一个表,里面有一个列是timestamp类型,我本意是在数据更新时,这个字段的时间能自动更新.岂知对这个类型的值还不甚了解,导致出错.发现这个字段只是在这行数据建立的时候有值,在更新的却无变化. 查找资料,发现是我建表的语句有问题: 以下是代码片段: CREATE TABLE `test` (  `t1` timestamp NOT NULL default CURRENT_TIMESTAMP,  `ww` varchar(5) NOT NULL) ENGINE=MyISAM ; 而实际

MYSQL ERROR

mysql出错了以前往往靠猜.有了这张表一查就出来了.方便不少.特共享于众 1005创建表失败 1006创建数据库失败 1007数据库已存在创建数据库失败 1008数据库不存在删除数据库失败 1009不能删除数据库文件导致删除数据库失败 1010不能删除数据目录导致删除数据库失败 1011删除数据库文件失败 1012不能读取系统表中的记录 1020记录已被其他用户修改 1021硬盘剩余空间不足请加大硬盘可用空间 1022关键字重复更改记录失败 1023关闭时发生错误 1024读文件错误 1025