복사되었습니다!
OS 환경 : Oracle Linux 8.7 (64bit)
DB 환경 : Oracle Database 19.27.0.0
에러 : ORA-02449: unique/primary keys in table referenced by foreign keys
테이블 삭제시 발생하는 에러
|
1
2
3
4
5
|
SQL> drop table employees;
drop table employees
*
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys
|
해결 방법 : cascade constraints 옵션 사용 또는 연관된 제약조건 먼저 제거 후 해당 테이블 제거
cascade constraints 옵션 사용 또는 연관된 제약조건 먼저 제거 후 해당 테이블 제거
방법1. drop 시 cascade constraints 옵션 사용
|
1
2
3
|
SQL> drop table employees cascade constraints;
Table dropped.
|
이 경우 연관된 테이블에 설정된 제약조건이 함께 삭제됨
방법2. 연관된 제약조건 제거
연관된 제약조건 확인
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
SQL>
set lines 200 pages 1000
col owner for a10
col child_table for a20
col parent_key_name for a30
col foreign_key_name for a30
select a.owner, a.table_name as child_table,
a.constraint_name as foreign_key_name, b.constraint_name as parent_key_name
from dba_constraints a, dba_constraints b
where a.r_constraint_name = b.constraint_name
and b.table_name = 'EMPLOYEES'
and a.constraint_type = 'R';
OWNER CHILD_TABLE FOREIGN_KEY_NAME PARENT_KEY_NAME
---------- -------------------- ------------------------------ ------------------------------
IMSI EMPLOYEES EMP_MANAGER_FK EMP_EMP_ID_PK
IMSI DEPARTMENTS DEPT_MGR_FK EMP_EMP_ID_PK
IMSI JOB_HISTORY JHIST_EMP_FK EMP_EMP_ID_PK
|
DEPARTMENTS 테이블에 DEPT_MGR_FK, JOB_HISTORY 테이블에 JHIST_EMP_FK 제약조건(FK)들이 설정되어 있음
제약조건 제거
|
1
2
3
4
5
6
7
|
SQL> alter table DEPARTMENTS drop constraint DEPT_MGR_FK;
Table altered.
SQL> alter table JOB_HISTORY drop constraint JHIST_EMP_FK;
Table altered.
|
employees 테이블 제거
|
1
2
3
|
SQL> drop table employees;
Table dropped.
|
정상적으로 제거됨
원인 : 제약조건이 걸려 있어 발생한 문제
제약조건이 걸려 있어 발생한 문제로 제약조건을 먼저 지워 준뒤 테이블을 삭제하면 잘 삭제됨
참조 :
'ORACLE > Trouble Shooting' 카테고리의 다른 글
| ORA-27086: unable to lock file - already in use (0) | 2024.04.24 |
|---|---|
| ORA-09968: unable to lock file (0) | 2024.04.20 |
| ORA-00441: Oracle Free Edition SID violation. Expected:free vs Actual:NON (0) | 2024.04.16 |
| ORA-01033: ORACLE initialization or shutdown in progress (0) | 2024.03.28 |
| AHF-00074: Required Perl Modules not found : Net::Ping (1) | 2024.03.21 |
