Casue:
When issuing truncate on a table we get the below error.
SQL> truncate table OWNER.TABLE;
truncate table OWNER.TABLE
*
ERROR at line 1:
ORA-02266: unique/primary keys in table referenced by enabled foreign keys
This is due to owner.table having reference with other table.
Use the below query to find the relationship.
set lines 200
col owner for a20
col status for a10
col deferrable for a15
col validated for a18
col generated for a15
col deferred for a15
select owner,constraint_name,constraint_type,table_name,status,DEFERRABLE,DEFERRED,VALIDATED,GENERATED from dba_constraints where table_name='TAB1' and constraint_type in ('R','P');
Solution:
Disable the constraints identified in the above query and execute the query again.
alter table OWNER_TABLE.TAB1 disable constraint PK_TAB1 cascade;
alter table OWNER_TABLE.TAB1 disable constraint FK_TAB1_30 cascade;
alter table OWNER_TABLE.TAB1 disable constraint FK_ERROR_3A cascade;
After that run the truncate.
SQL> truncate table OWNER.TABLE;
When issuing truncate on a table we get the below error.
SQL> truncate table OWNER.TABLE;
truncate table OWNER.TABLE
*
ERROR at line 1:
ORA-02266: unique/primary keys in table referenced by enabled foreign keys
This is due to owner.table having reference with other table.
Use the below query to find the relationship.
set lines 200
col owner for a20
col status for a10
col deferrable for a15
col validated for a18
col generated for a15
col deferred for a15
select owner,constraint_name,constraint_type,table_name,status,DEFERRABLE,DEFERRED,VALIDATED,GENERATED from dba_constraints where table_name='TAB1' and constraint_type in ('R','P');
Solution:
Disable the constraints identified in the above query and execute the query again.
alter table OWNER_TABLE.TAB1 disable constraint PK_TAB1 cascade;
alter table OWNER_TABLE.TAB1 disable constraint FK_TAB1_30 cascade;
alter table OWNER_TABLE.TAB1 disable constraint FK_ERROR_3A cascade;
After that run the truncate.
SQL> truncate table OWNER.TABLE;