How to set to NULL a datetime with 0000-00-00 00:00:00 value?

后端 未结 5 1669
夕颜
夕颜 2021-02-08 18:37

I need to change a few values on my DB.

I forgot to set nullable to the table and it set to 0000-00-00 00:00:00 by default.

Now I need to convert that value in <

5条回答
  •  星月不相逢
    2021-02-08 19:36

    From MySQL 5.7, SQL mode NO_ZERO_DATE makes this update impossible unless you firstly disable this restriction (for the duration of the transaction only).

    SET sql_mode=(SELECT REPLACE(@@sql_mode,"NO_ZERO_DATE", ""));
    UPDATE mytable SET field = NULL WHERE field = '0000-00-00 00:00:00';
    

提交回复
热议问题