MySQL - employ created_date and updated_date?
In MySQL, is there an easy way for the following:
- On creation, both
created_date
andupdated_date
are set to the sameTIMESTAMP
- On subsequent edits,
updated_date
is changed to theCURRENT_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.
精彩评论