添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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?

A late answer for others who may Google this: if you use a TIMESTAMP when you do manuals edits in your database; or if you have multiple TIMESTAMP columns and do not want to touch all of them; the MySQL manual says to assign the column to itself. You explicitly set the column to its current value (ie. "updated_on = updated_on"), so that it is not changed by the UPDATE. user58777 Nov 12, 2010 at 16:22

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
                I may be missing something but my table is (and was) defined this way but still the dates changed. From mysql explain: 'pur_time', 'timestamp', 'NO', '', 'CURRENT_TIMESTAMP', ''
– Nir
                May 3, 2009 at 16:34
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.