2011-06-22 24 views
0

Possible Duplicate:
Having both a Created and Last Updated timestamp columns in MySQL 4.0如何制作多个CURRENT_TIMESTAMP列?

假设我想在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

我怎样才能解决这个问题?

+0

解答如下:http://stackoverflow.com/questions/267658/having-both-a-created-and-last-updated-timestamp-columns-in-mysql-4-0 – Jacob

+0

@cularis:抓到好,投票重复 –

回答

1

根据这一DB之上有什么,你也可以留下NULL默认值(或一组lastVisit列)时间戳字段,然后只需要确保,在您的INSERT查询,您使用

firstVisit = NOW() 

对于我使用过的其他系统,我有类似的约束,并且我们总是使用应用程序级代码实现这种逻辑,以在INSERT中引入当前时间戳。