Remove all zero dates from MySQL database across all Tables

前端 未结 9 1495
-上瘾入骨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:37

    As this is for migration, I would suggest that you simply wrap your tables in views which does the conversion as you export the data. I have used the below concept moving data from MySQL to postgress which has the same problem.

    Each table should be proxied by something like this;

    CREATE VIEW migration_mytable AS 
    SELECT field1, field2, 
        CASE field3
             WHEN '0000-00-00 00:00:00' 
             THEN '1900-01-01 00:00:00' 
             ELSE field3
        END CASE AS field3
    FROM mytable;
    

    You should be able to write a script which generate this for you from the catalog, in case you have a great deal of tables to take care of.

    You should then be able to import the data into your SqlServer table (using a bridge like this), and simply running a query like;

    INSERT INTO sqlserver.mytable SELECT * FROM mysql.migration_mytable;
    

提交回复
热议问题