Stop automatic updating for MySQL datestamp

551 views Asked by At

I have a datetime column called create_date. When I create a row, I enter the date NOW().

However, when I update a row my create_date column automatically updates to NOW(). Even if I was setting different columns and not touching create_date, it still gets updated. How can I stop this behavior?

Found this doc, but it doesn't explain how to stop the automatic updating. http://dev.mysql.com/doc/refman/5.0/en/timestamp-initialization.html

1

There are 1 answers

0
hichris123 On BEST ANSWER

Try changing the schema so that it uses the DEFAULT clause, which sets it on creation but not on an update:

ALTER TABLE tablename MODIFY COLUMN columnamre TIMESTAMP DEFAULT CURRENT_TIMESTAMP