MySQL set current date in a DATETIME field on insert

后端 未结 4 1688
迷失自我
迷失自我 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:14

    Using Now() is not a good idea. It only save the current time and date. It will not update the the current date and time, when you update your data. If you want to add the time once, The default value =Now() is best option. If you want to use timestamp. and want to update the this value, each time that row is updated. Then, trigger is best option to use.

    1. http://www.mysqltutorial.org/sql-triggers.aspx
    2. http://www.tutorialspoint.com/plsql/plsql_triggers.htm

    These two toturial will help to implement the trigger.

提交回复
热议问题