MySQL set current date in a DATETIME field on insert

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

    DELIMITER ;;
    CREATE TRIGGER `my_table_bi` BEFORE INSERT ON `my_table` FOR EACH ROW
    BEGIN
        SET NEW.created_date = NOW();
    END;;
    DELIMITER ;
    

提交回复
热议问题