티스토리 뷰

반응형

MySQL에서 Table의 Data를 Delete할 때 다음의 에러를 만나는 경우가 있다.

Error Code: 1175
You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column

이 에러와 관련된 공식 문서의 내용은 다음과 같다.

4.5.1.6.4 Using the --safe-updates Option

For beginners, a useful startup option is --safe-updates (or --i-am-a-dummy, which has the same effect). It is helpful for cases when you might have issued a DELETE FROM tbl_name statement but forgotten the WHERE clause. Normally, such a statement deletes all rows from the table. With --safe-updates, you can delete rows only by specifying the key values that identify them. This helps prevent accidents.

해석하자면 DELETE Query를 할 때 WHERE clause가 없다면 테이블의 모든 데이터를 delete하게 되는데 이런 사고를 방지하기 위해 --safe-update 옵션을 사용한다는 뜻이다.

이 문제를 해결하기 위해서는 WHERE절을 이용하여 모든 데이터를 삭제하거나 WHERE절을 쓰기 싫을 경우 다음을 한번 실행시킨 뒤 다시 DELETE Query를 하면 된다.

SET SQL_SAFE_UPDATES=0;


반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함