Alex Rivera | Logout

MySQL timestamp only on create

Asked 2009-05-03T16:09:04.243
41

I use timestamp on MySQL 5.x (with PHP) to remember event times. During development I had to update the table with a query that changes something in all columns. The timestamp was then reset to current time.

How can I make timestamp change only on inserts and not on updates or replace?

Edit
Report

1 Answer

79

Here's all you need to know. In short, though, I think this should do it:

ALTER TABLE `mytable`
CHANGE `mydatefield` `mydatefield`
TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
answered 2009-05-03T16:12:54.593

Your Answer