Remove all zero dates from MySQL database across all Tables

前端 未结 9 1591
-上瘾入骨i
-上瘾入骨i 2021-01-13 14:37

I have plenty of tables in MySQL which which contains zero date in dateTime column 0000-00-00 00:00:00

Using some sort of admin settings, Is it possibl

9条回答
  •  甜味超标
    2021-01-13 14:43

    In my opinion, you could generate all updates the simplest way:

    select
    concat('UPDATE ',TABLE_NAME,' SET ',COLUMN_NAME,'=NULL WHERE ',COLUMN_NAME,'=0;')
    from information_schema.COLUMNS 
    where TABLE_SCHEMA = 'DATABASE_NAME' and DATA_TYPE in ('datetime', 'date', 'time');
    

    Just replace DATABASE_NAME to your DB name, and execute all updates.

提交回复
热议问题