Possible Duplicate:
Having both a Created and Last Updated timestamp columns in MySQL 4.0
假设我想将首次访问和最后访问时间存储在MySQL数据库中。
从逻辑上讲,我应该添加 CURRENT_TIMESTAMP 作为firstVisit 的默认属性,并且 LastVisit 列的“更新 CURRENT_TIMESTAMP”属性。
但是它给了我以下 mysql 错误:
Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
我该如何解决这个问题?
最佳答案
根据此数据库顶部的内容,您还可以将时间戳字段保留为 NULL 默认值(或设置 lastVisit 列),然后确保在 INSERT 查询中使用
firstVisit = NOW()
我在使用过的其他系统上也有类似的限制,并且我们总是使用应用程序级代码实现这种逻辑,以在 INSERT 上引入当前时间戳。
关于mysql - 如何创建多个 CURRENT_TIMESTAMP 列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6440171/