Skip to content
Home » Oracle » How to Resolve ORA-02449: unique/primary keys in table referenced by foreign keys

How to Resolve ORA-02449: unique/primary keys in table referenced by foreign keys

ORA-02449

Tried to drop a table, but it failed with ORA-02449.

SQL> show user
USER is "HR"
SQL> drop table employees;
drop table employees
           *
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys

ORA-02449 means that the table you want to drop has some referential relationship between tables, which may affect data integrity if you drop the table.

Solution

To check what foreign key constraints are related to the table, you may perform a query by a privileged user:

SQL> show user
USER is "SYS"
SQL> column owner format a10;
SQL> column table_name format a20;
SQL> column constraint_name format a50;
SQL> select owner, table_name, constraint_name from all_constraints where r_owner = 'HR' and r_constraint_name in (select constraint_name from all_constraints where owner = 'HR' and table_name = 'EMPLOYEES') order by 1,2,3;

OWNER      TABLE_NAME           CONSTRAINT_NAME
---------- -------------------- ------------------------------
HR         DEPARTMENTS          DEPT_MGR_FK
HR         EMPLOYEES            EMP_MANAGER_FK
HR         JOB_HISTORY          JHIST_EMP_FK
OE         CUSTOMERS            CUSTOMERS_ACCOUNT_MANAGER_FK
OE         ORDERS               ORDERS_SALES_REP_FK

To find the referential relationships between referencing and referenced columns of a table, we have a way to do it.

Now you have 2 options.

Keep it

If you need it to maintains important referential integrity, then don't drop it. You may try another way around.

Drop it

If you don't need it, then you can drop it with CASCADE CONSTRAINTS.

SQL> drop table employees cascade constraints;

Table dropped.

We dropped it.

Leave a Reply

Your email address will not be published. Required fields are marked *