MySQL--建立时间和更新时间字段

这是我写的第一篇技术博客, 刚刚毕业, 已经投入工做快一个月了, 写一下刚刚遇到的问题, 在建立数据库的时候, 我在一个表中须要建立时间和更新时间这两个字段, 因此sql命令以下:web

 `release_time` timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '发布时间', 
`update_time` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',

点击运行, 数据库发来了错误警示sql

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

网上查找了一下缘由, 我在本地测试用的数据库是MySQL版本5.5, 在MySQL 5.5的文档中有这么一段话数据库

One TIMESTAMP column in a table can have the current timestamp as the default value for

initializing the column, as the auto-update value, or both. It is not possible to have the

current timestamp be the default value for one column and the auto-update value for another column.

意思就是在一个表中只能有一个TIMESTAMP类型字段能够有CURRENT_TIMESTAMP做为默认值.svg

在MySQL-5.6.1有以下改变:测试

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或者DATETIME类型字段将CURRENT_TIMESTAMP做为默认值了.ui