Quantcast
Channel: Doyensys Allappsdba Blog..
Viewing all articles
Browse latest Browse all 1640

ORA-02266: unique/primary keys in table referenced by enabled foreign keys

$
0
0
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;





Viewing all articles
Browse latest Browse all 1640

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>