슬기로운생활/Database
ORA-02292: 무결성 제약조건(OWNER.SYS_CODE)이 위배되었습니다- 자식 레코드가 발견되었습니다
좀모씨
2009. 12. 3. 21:46
테이블이 FK로 묶여있을 때 상위테이블에서 데이터를 삭제하려고 하면 볼 수 있는 에러.
매칭된 컬럼을 보고 싶다면 아래의 쿼리를 날려주자.
SELECT PARENTCOLS.OWNER || '.' || PARENT.TABLE_NAME || '.' || PARENTCOLS.COLUMN_NAME || ' matches to ' || CHILDCOLS.OWNER || '.' || CHILD.TABLE_NAME || '.' || CHILDCOLS.COLUMN_NAME
FROM ALL_CONS_COLUMNS CHILDCOLS, ALL_CONS_COLUMNS PARENTCOLS, ALL_CONSTRAINTS CHILD, ALL_CONSTRAINTS PARENT
WHERE CHILDCOLS.OWNER = 'OWNER'
AND CHILDCOLS.CONSTRAINT_NAME = 'SYS_CODE'
AND CHILDCOLS.OWNER = CHILD.OWNER
AND CHILDCOLS.CONSTRAINT_NAME = CHILD.CONSTRAINT_NAME
AND CHILD.R_OWNER = PARENT.OWNER
AND CHILD.R_CONSTRAINT_NAME = PARENT.CONSTRAINT_NAME
AND PARENT.OWNER = PARENTCOLS.OWNER
AND PARENT.CONSTRAINT_NAME = PARENTCOLS.CONSTRAINT_NAME
AND CHILDCOLS.POSITION = PARENTCOLS.POSITION
ORDER BY CHILDCOLS.POSITION;