Oracle 23.26ConstraintsLab-verified · 2026-11-19

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

DROP TABLE failed because another table has a foreign key pointing at this table's primary or unique key.

Oracle AI Database 26ai Free 23.26.3.0.0
ORA-02449: unique/primary keys in table referenced by foreign keys

Jump to a cause

  1. 01Dropping the parent table before the child table
  2. 02Rebuilding the parent table while keeping the child table
  3. 03A table in another schema refers to the table

Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-19 · container image gvenzl/oracle-free:23-slim

ORA-02449 comes from DROP TABLE. The table you are dropping is a parent: some foreign key refers to its primary key. Oracle will not leave that foreign key pointing at nothing, so the table is not dropped.

The message does not say which table refers to it. First find the foreign key in the dictionary, then decide: drop the child table too, keep the child and remove only the constraint, or ask the owner of another schema.

01Dropping the parent table before the child table

ORDERS.CUST_ID refers to CUSTOMERS, so DROP TABLE customers fails. Joining USER_CONSTRAINTS to itself on r_constraint_name shows the referring constraint: ORDERS_CUST_FK on ORDERS.

When both tables should go (for example in a cleanup or re-install script), drop the child first. In that order both DROP TABLE statements succeeded and no table remained.

Setup
Setuprun as lab_a
CREATE TABLE customers (cust_id NUMBER CONSTRAINT customers_pk PRIMARY KEY, name VARCHAR2(30));
CREATE TABLE orders (order_id NUMBER CONSTRAINT orders_pk PRIMARY KEY, cust_id NUMBER CONSTRAINT orders_cust_fk REFERENCES customers, amount NUMBER);
INSERT INTO customers VALUES (1, 'Kim');
INSERT INTO orders VALUES (1001, 1, 500);
COMMIT;
OUTPUT
Table created.


Table created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
DROP TABLE customers PURGE;
✕ ERROR
DROP TABLE customers PURGE
           *
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys
Help: https://docs.oracle.com/error-help/db/ora-02449/
Checkrun as lab_a
COLUMN constraint_name FORMAT A16
COLUMN child_table FORMAT A12
COLUMN parent_table FORMAT A12
SELECT c.constraint_name, c.table_name AS child_table, p.table_name AS parent_table
  FROM user_constraints c JOIN user_constraints p ON p.constraint_name = c.r_constraint_name
 WHERE c.constraint_type = 'R'
   AND p.table_name = 'CUSTOMERS';
OUTPUT
CONSTRAINT_NAME  CHILD_TABLE  PARENT_TABLE
---------------- ------------ ------------
ORDERS_CUST_FK   ORDERS       CUSTOMERS

1 row selected.

In drop scripts, list child tables before parent tables.

After the fixrun as lab_a
DROP TABLE orders PURGE;
DROP TABLE customers PURGE;
SELECT COUNT(*) AS remaining FROM user_tables WHERE table_name IN ('ORDERS', 'CUSTOMERS');
✓ SUCCESS
Table dropped.


Table dropped.


 REMAINING
----------
         0

1 row selected.

02Rebuilding the parent table while keeping the child table

Sometimes only the parent is recreated and the child data must stay. Before the change, ORDERS had ORDERS_CUST_FK (R) and ORDERS_PK (P).

DROP TABLE customers CASCADE CONSTRAINTS drops the parent together with the foreign keys that refer to it. Afterwards ORDERS had only ORDERS_PK, and the order row 1001 was still there.

Setup
Setuprun as lab_a
CREATE TABLE customers (cust_id NUMBER CONSTRAINT customers_pk PRIMARY KEY, name VARCHAR2(30));
CREATE TABLE orders (order_id NUMBER CONSTRAINT orders_pk PRIMARY KEY, cust_id NUMBER CONSTRAINT orders_cust_fk REFERENCES customers, amount NUMBER);
INSERT INTO customers VALUES (1, 'Kim');
INSERT INTO orders VALUES (1001, 1, 500);
COMMIT;
OUTPUT
Table created.


Table created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
DROP TABLE customers PURGE;
✕ ERROR
DROP TABLE customers PURGE
           *
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys
Help: https://docs.oracle.com/error-help/db/ora-02449/
Checkrun as lab_a
COLUMN constraint_name FORMAT A16
SELECT constraint_name, constraint_type FROM user_constraints WHERE table_name = 'ORDERS' ORDER BY constraint_name;
OUTPUT
CONSTRAINT_NAME  C
---------------- -
ORDERS_CUST_FK   R
ORDERS_PK        P

2 rows selected.

CASCADE CONSTRAINTS removes the foreign key silently. After recreating the parent, add the foreign key back, or the child is no longer checked.

After the fixrun as lab_a
DROP TABLE customers CASCADE CONSTRAINTS PURGE;
COLUMN constraint_name FORMAT A16
SELECT constraint_name, constraint_type FROM user_constraints WHERE table_name = 'ORDERS' ORDER BY constraint_name;
SELECT order_id, cust_id, amount FROM orders;
✓ SUCCESS
Table dropped.


CONSTRAINT_NAME  C
---------------- -
ORDERS_PK        P

1 row selected.


  ORDER_ID    CUST_ID     AMOUNT
---------- ---------- ----------
      1001          1        500

1 row selected.

03A table in another schema refers to the table

LAB_B.STAFF has a foreign key to LAB_A.DEPTS. Searching from LAB_A with ALL_CONSTRAINTS returned no rows selected, because LAB_A has no privilege on LAB_B's table. As a DBA, DBA_CONSTRAINTS with r_owner = 'LAB_A' found STAFF_DEPT_FK on LAB_B.STAFF.

After LAB_B dropped that constraint, DROP TABLE depts succeeded.

Setup
Setuprun as lab_a
CREATE TABLE depts (dept_id NUMBER CONSTRAINT depts_pk PRIMARY KEY, dept_name VARCHAR2(30));
INSERT INTO depts VALUES (10, 'Sales');
COMMIT;
GRANT REFERENCES, SELECT ON depts TO lab_b;
OUTPUT
Table created.


1 row created.


Commit complete.


Grant succeeded.
Setuprun as lab_b
CREATE TABLE staff (staff_id NUMBER PRIMARY KEY, dept_id NUMBER CONSTRAINT staff_dept_fk REFERENCES lab_a.depts);
INSERT INTO staff VALUES (1, 10);
COMMIT;
OUTPUT
Table created.


1 row created.


Commit complete.
Reproducerun as lab_a
DROP TABLE depts PURGE;
✕ ERROR
DROP TABLE depts PURGE
           *
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys
Help: https://docs.oracle.com/error-help/db/ora-02449/
Checkrun as lab_a
COLUMN owner FORMAT A8
COLUMN constraint_name FORMAT A16
COLUMN table_name FORMAT A10
SELECT owner, constraint_name, table_name
  FROM all_constraints
 WHERE constraint_type = 'R'
   AND r_owner = 'LAB_A'
   AND r_constraint_name = 'DEPTS_PK';
OUTPUT
no rows selected
Checkrun as system
COLUMN owner FORMAT A8
COLUMN constraint_name FORMAT A16
COLUMN table_name FORMAT A10
SELECT owner, constraint_name, table_name
  FROM dba_constraints
 WHERE constraint_type = 'R'
   AND r_owner = 'LAB_A'
   AND r_constraint_name = 'DEPTS_PK';
OUTPUT
OWNER    CONSTRAINT_NAME  TABLE_NAME
-------- ---------------- ----------
LAB_B    STAFF_DEPT_FK    STAFF

1 row selected.
Fixrun as lab_b
ALTER TABLE staff DROP CONSTRAINT staff_dept_fk;
OUTPUT
Table altered.

If you cannot find the child table in your own schema, ask a DBA to search DBA_CONSTRAINTS by r_owner and r_constraint_name.

After the fixrun as lab_a
DROP TABLE depts PURGE;
✓ SUCCESS
Table dropped.

FAQ

How do I find which table references the table I want to drop?

Search USER_CONSTRAINTS (or DBA_CONSTRAINTS) for constraint_type = 'R' whose r_constraint_name is the parent's primary key. The table_name of that row is the child table.

What does DROP TABLE ... CASCADE CONSTRAINTS do?

It drops the table and the foreign keys in other tables that refer to it. The child tables and their data stay. In the test, ORDERS kept its row and lost only ORDERS_CUST_FK.

I can't find any foreign key, but ORA-02449 still occurs.

The child table may be in another schema. From your own account ALL_CONSTRAINTS returned no rows in the test; DBA_CONSTRAINTS found it.

What is the difference between ORA-02449 and ORA-02292?

ORA-02292 is for deleting parent rows that have child rows. ORA-02449 is for dropping the whole parent table while a foreign key refers to it.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0