MySQL set current date in a DATETIME field on insert

后端 未结 4 1692
迷失自我
迷失自我 2020-12-13 19:55

I have a \'created_date\' DATETIME field which I would like to be populated with the current date upon insert. What syntax should I use for the trigger for this? This is wha

4条回答
  •  长情又很酷
    2020-12-13 20:04

    Your best bet is to change that column to a timestamp. MySQL will automatically use the first timestamp in a row as a 'last modified' value and update it for you. This is configurable if you just want to save creation time.

    See doc http://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html

提交回复
热议问题