How do I change all empty strings to NULL in a table?

前端 未结 7 1506
悲哀的现实
悲哀的现实 2020-12-08 20:25

I have a legacy table with about 100 columns (90% nullable). In those 90 columns I want to remove all empty strings and set them to null. I know I can:

updat         


        
7条回答
  •  自闭症患者
    2020-12-08 20:57

    Hammerite's answer is good but you can also replace CASE statements with IFs.

    UPDATE
        TableName
    SET
        column01 = IF(column01 = '', NULL, column01),
        column02 = IF(column02 = '', NULL, column02),
        column03 = IF(column03 = '', NULL, column03),
        ...,
        column99 = IF(column99 = '', NULL, column99)
    

提交回复
热议问题