mysql单表多timestamp的current_timestamp设置问题
2016-05-07 11:30
645 查看
mysql单表多timestamp的current_timestamp设置问题
一个表中出现多个timestamp并设置其中一个为current_timestamp的时候经常会遇到
#1293 - Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
原因是当你给一个timestamp设置为on update current_timestamp的时候,其他的timestamp字段需要显式设定default值
但是如果你有两个timestamp字段,但是只把第一个设定为current_timestamp而第二个没有设定默认值,mysql也能成功建表, 但是反过来就不行.
eg:
CREATE TABLE `users` (
`iUId` int(10) unsigned NOT NULL AUTO_INCREMENT,
`szUsername` varchar(45) NOT NULL,
`szEmail` varchar(60) DEFAULT NULL,
`szPassword` varchar(64) NOT NULL,
`szInsertTime` timestamp NOT NULL DEFAULT 0,
`szLastModTime` timestamp ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`iStatus` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`iUId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
一个表中出现多个timestamp并设置其中一个为current_timestamp的时候经常会遇到
#1293 - Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
原因是当你给一个timestamp设置为on update current_timestamp的时候,其他的timestamp字段需要显式设定default值
但是如果你有两个timestamp字段,但是只把第一个设定为current_timestamp而第二个没有设定默认值,mysql也能成功建表, 但是反过来就不行.
eg:
CREATE TABLE `users` (
`iUId` int(10) unsigned NOT NULL AUTO_INCREMENT,
`szUsername` varchar(45) NOT NULL,
`szEmail` varchar(60) DEFAULT NULL,
`szPassword` varchar(64) NOT NULL,
`szInsertTime` timestamp NOT NULL DEFAULT 0,
`szLastModTime` timestamp ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`iStatus` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`iUId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
相关文章推荐
- Mysql中约束详解
- zabbix网页安装过程中mysql的sock报错
- MySQL流程控制实例
- MySQL 存储引擎(MyISAM、InnoDB、NDBCluster)
- Mysql备份、恢复
- 数据挖掘之weka连接mysql数据库
- MySQL数据库服务器的架设
- mysql 5.6.30安装配置
- 162 mysql Access denied for user 'root'@'localhost'
- mysql cluster的常见问题
- .AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z错误
- MySQL InnoDB引擎索引长度受限怎么办?
- mac mysql root 初始密码 过期
- 解决mysql 客户端连接问题
- MySQL数据库分区功能的使用教程
- MySQL知识的持续汇总
- MySQL数据库服务器的架设
- Mac 下 Mysql 重置密码
- mysql 聚簇索引 和聚簇索引 (二级索引)的 那些事
- MySQL数据库服务器的架设