开发者

MySQL - employ created_date and updated_date?

开发者 https://www.devze.com 2023-02-07 06:01 出处:网络
In MySQL, is there an easy way for the following: On creation, both created_date and updated_date are set to the same TIMESTAMP

In MySQL, is there an easy way for the following:

  • On creation, both created_date and updated_date are set to the same TIMESTAMP
  • On subsequent edits, updated_date is changed to the CURRENT_TIMESTAMP

Why is only one field allowed to use the CURRENT_TIMESTAMP as its default value? Why can't I have one default to the CURRENT_TIMESTAMP and the other use it only on update?

If I use now() for created_date and on update CURRENT_TIMESTA开发者_运维百科MP for updated_date, will they be the same on the creation of a row?


That's just the way it is :)

But seriously, it's usually easier (less surprises) when you set those dates explicitly with 'now()' when you create/update the row.

0

精彩评论

暂无评论...
验证码 换一张
取 消