오늘도 한 뼘 더

[MySQL] Error Code 1175: Safe Update 해결 방법 본문

Study/MySQL

[MySQL] Error Code 1175: Safe Update 해결 방법

나른한댕댕이🐶 2022. 4. 1. 10:12
728x90
반응형

  # 배경  

회사에서 데이터 관련 작업을 진행하는데 update문을 작성하는 중 workbench에서 다음과 같은 에러가 뜨고 실행되지 않는 문제가 발생했다. 

Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column.  To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnect.

 

  # 해결 방법  

작동하려고 한 코드

  update item set quantity=0 where quantity is null;

1) 일시적으로 safe update를 해제시키는 방법

다음 코드를 update문을 실행 시키기 전 실행하면 safe update가 해제되면서 update가 가능해진다.

  set sql_safe_updates=0;

 

2) 코드 자체적으로 수정해서 진행하는 방법

id 가 0보다 크다는 걸 명시해주면 불안정한 상태를 막아준다. 이렇게 작성하면 제한을 풀지 않아도 실행이 된다.

  update item set quantity=0 where quantity is null and id > 0;
728x90
반응형
Comments