Setting value for one column of all records in table

后端 未结 1 1626
你的背包
你的背包 2020-12-24 10:49

I\'m trying to clear one column for all records in my table. For example, if my table had three columns: id, comment, and likes - I wo

相关标签:
1条回答
  • 2020-12-24 11:24
    UPDATE your_table SET likes = NULL
    

    or if your likes column does not allow NULL:

    UPDATE your_table SET likes = ''
    

    Some SQL tools that are used for executing DB queries prevent updates on ALL records (queries without a where clause) by default. You can configure that and remove that savety setting or you can add a where clause that is true for all records and update all anyway like this:

    UPDATE your_table 
    SET likes = NULL
    WHERE 1 = 1
    

    If you compare with NULL then you also need the IS operator. Example:

    UPDATE your_table 
    SET likes = NULL
    WHERE likes IS NOT NULL
    

    because comparing NULL with the equal operator (=) returns UNKNOWN. But the IS operator can handle NULL.

    0 讨论(0)
提交回复
热议问题