Problem: When trying to truncate a table, getting below error
SQL> truncate table PROD.CUSTOMER;
truncate table PROD.CUSTOMER
ERROR at line 1:
ORA-02266: unique/primary keys in table referenced by enabled foreign keys
Solution: This error comes when we are trying to truncate a table which is a parent in a referential integrity. Before you truncate this parent table, you have to disable constraints on the child tables.
The below query will help you to get information about dependent constraints:
select ‘ALTER TABLE ‘ || OWNER || ‘.’ || TABLE_NAME||’ DISABLE CONSTRAINT ‘||CONSTRAINT_NAME||’;’ from dba_constraints
where R_CONSTRAINT_NAME='<Primary Key Constraint name from CUSTOMER table>’;
Once the above query returns disable commands, run the disable constraints, then try to drop Truncate table. It should work at this time!
Credits: The query is taken from http://stackoverflow.com/questions/4812146/truncate-table-in-oracle-getting-errors