开发者

MySQL - employ created_date and updated_date?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜