Skip to main content
added 136 characters in body
Source Link
Rudy De Volder
  • 2.1k
  • 1
  • 12
  • 5

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 likeas you expect.

No need to set SQL_SAFE_UPDATES to 0, I would really discourage it to do it that way. 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 updated like you expect.

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.

deleted 178 characters in body
Source Link
Rudy De Volder
  • 2.1k
  • 1
  • 12
  • 5

No need to set SAFE_SQL_SAFE_UPDATESSQL_SAFE_UPDATES to 0, I would really discourage it to do it that way because:

it's very dangerous

when updating tables this way without sequencially using a key, that's the reason it's default 'ON' to protect you from making mistakes!. 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 updated like you expect.

No need to set SAFE_SQL_SAFE_UPDATES to 0, I would really discourage it to do it that way because:

it's very dangerous

when updating tables this way without sequencially using a key, that's the reason it's default 'ON' to protect you from making mistakes! 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 updated like you expect.

No need to set SQL_SAFE_UPDATES to 0, I would really discourage it to do it that way. 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 updated like you expect.

Source Link
Rudy De Volder
  • 2.1k
  • 1
  • 12
  • 5

No need to set SAFE_SQL_SAFE_UPDATES to 0, I would really discourage it to do it that way because:

it's very dangerous

when updating tables this way without sequencially using a key, that's the reason it's default 'ON' to protect you from making mistakes! 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 updated like you expect.