使用一个查询更新SQL中的所有行

例如,我想更新所有行;

UPDATE table_name
SET column= '0'
WHERE id IN (1,2,3,4,5,6,7,8,9.....)

就像这样,我可以手动输入id,但是我想要这样;

UPDATE table_name
SET column= '0'
WHERE id IN (ALL)

有什么疑问吗?

评论
  • 再次邂逅i
    再次邂逅i 回复

    If you want to update all rows just don't use any WHERE clause at all.

    UPDATE table_name
           SET column = '0';
    
  • 依、太难
    依、太难 回复

    这应该更新所有行:

    UPDATE table_name
        SET column = '0';
    

    The WHERE clause is not needed.

    I should note that MySQL has a "safety" mode called SQL_SAFE_UPDATES which only allows UPDATE statements with a WHERE clause. You may need to disable this:

    SET SQL_SAFE_UPDATES = 0;
    

    或使用:

    WHERE id >= 0
    

    或一些将选择所有ID的类似逻辑。

    Here is a db<>fiddle that illustrates this.