MySQL timestamp only on create

后端 未结 3 1798
谎友^
谎友^ 2020-12-14 06:20

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 timesta

相关标签:
3条回答
  • 2020-12-14 06:55

    You can use a default value for that field and not include it in the insert or update query.

    0 讨论(0)
  • 2020-12-14 06:56

    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
    
    0 讨论(0)
  • 2020-12-14 06:56
    ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    

    Very good documentation here for time-stamp.

    0 讨论(0)
提交回复
热议问题