0

Possible Duplicate:
Having both a Created and Last Updated timestamp columns in MySQL 4.0

Suppose I want to store first visit and last visit time in MySQL database.

Logically, I should add CURRENT_TIMESTAMP as a default attribute for firstVisit and "on update CURRENT_TIMESTAMP" attribute for lastVisit column.

But it gives me the following mysql error:

Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

How can I fix this?

Community
  • 1
  • 1
tsds
  • 8,700
  • 12
  • 62
  • 83

1 Answers1

1

Depending on what's on top of this DB, you could also leave the timestamp fields with NULL defaults (or set lastVisit column) and then just make sure that, in your INSERT query, you use

firstVisit = NOW()

I've had similar constraints on other systems I've worked with, and we always implemented that sort of logic with application-level code to bring in the current timestamp on INSERT.

Sean
  • 564
  • 1
  • 3
  • 12