layout: post title: insert trigger사용시 주의 categories: mysql tags: mysql –

Can’t update table ‘xxx’ in stored function/trigger because it is already used by statement which invoked this stored function/trigger

테이블에 after insert 트리거로 로그테이블을 만들어 사용중이다.

운영 테이블에 문제가 생겨 로그 테이블에서 데이터를 바로 운영테이블로 insert하려고 했는데

Can’t update table ‘xxx’ in stored function/trigger because it is already used by statement which invoked this stored function/trigger

이라는 메시지가 출력이 됐다.

insert트리거가 실행되는 동안에 테이블을 변경할 수 없고, 잘못하다가 무한 루프에빠질 수도 있기때문에다.(재귀)

그래서 로그테이블을 복사한다음에 그걸로 insert함.