MySQL error code: 1175 during UPDATE in MySQL Workbench

前端 未结 20 1246
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 09:58

I\'m trying to update the column visited to give it the value 1. I use MySQL workbench, and I\'m writing the statement in the SQL editor from inside the workben

20条回答
  •  迷失自我
    2020-11-22 10:55

    No need to set SQL_SAFE_UPDATES to 0, I would really discourage it to do it that way. SAFE_UPDATES is by default on for a REASON. You can drive a car without safety belts and other things if you know what I mean ;) Just add in the WHERE clause a KEY-value that matches everything like a primary-key comparing to 0, so instead of writing:

    UPDATE customers SET countryCode = 'USA'
        WHERE country = 'USA';               -- which gives the error, you just write:
    
    UPDATE customers SET countryCode = 'USA'
        WHERE (country = 'USA' AND customerNumber <> 0); -- Because customerNumber is a primary key you got no error 1175 any more.
    

    Now you can be assured every record is (ALWAYS) updated as you expect.

提交回复
热议问题