[문제]

특정 테이블을 drop 하고 싶은데 ORA-02449 오류로 삭제 할 수 없다. "외래 키에 의해 참조되는 고유/기본 키가 테이블이 있습니다." 라는 오류 때문이다. 

명령의 1 행에서 시작하는 중 오류 발생 -
drop table member
오류 보고 -
ORA-02449: 외래 키에 의해 참조되는 고유/기본 키가 테이블에 있습니다
02449. 00000 -  "unique/primary keys in table referenced by foreign keys"
*Cause:    An attempt was made to drop a table with unique or
           primary keys referenced by foreign keys in another table.
*Action:   Before performing the above operations the table, drop the
           foreign key constraints in other tables. You can see what
           constraints are referencing a table by issuing the following
           command:
           SELECT * FROM USER_CONSTRAINTS WHERE TABLE_NAME = "tabnam";

CONSTRAINT_NAME

 

[원인 찾기]

우선 어떤 것들이 참조 되고 있는지를 확인하기 위해 아래와 같이 명령을 해준다. 

 

SELECT constraint_name, table_name
FROM user_constraints
WHERE r_constraint_name IN (
    SELECT constraint_name
    FROM user_constraints
    WHERE table_name = '지우고자 했던 테이블이름' AND constraint_type IN ('P', 'U')
);

 

그러면 아래와 같이 결과가 나온다. 

 

 

[해결]

나온 결과에 있는 외래키들을 전부 삭제 시켜주어야 한다. 

ALTER TABLE 검색해서 나왔던TABLE_NAME DROP CONSTRAINT 검색해서 나왔던 CONSTRAINT_NAME 값 ;
ex) ALTER TABLE CHAT DROP CONSTRAINT FKL3J4IWRC60BK7G6A1NQSH401Y;

 

[결과]

전부 삭제 시켜주면 테이블이 모두 변경 되었다 나오고 아까 지우려던 table 도 문제 없이 잘 drop 된다. 

해니01_15