Oracle 23.26ConstraintsLab-verified · 2026-11-27

ORA-02273: this unique/primary key is referenced by some foreign keys

A foreign key still points at the primary or unique key you are trying to drop.

Oracle AI Database 26ai Free 23.26.3.0.0
ORA-02273: this unique/primary key is referenced by some foreign keys

Jump to a cause

  1. 01A child table's foreign key references the primary key
  2. 02A foreign key references a UNIQUE constraint, not the primary key
  3. 03The foreign key is in another schema, so you cannot see it

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

Oracle will not drop a primary key or unique constraint while a foreign key references it, because the foreign key would have nothing to check against. ALTER TABLE then fails with ORA-02273.

Below are three common cases reproduced on a real database, with the fix we ran and its result.

01A child table's foreign key references the primary key

emp.dept_id had CONSTRAINT emp_dept_fk REFERENCES dept. Running ALTER TABLE dept DROP PRIMARY KEY failed with ORA-02273.

Querying user_constraints for constraint_type = 'R' and r_constraint_name = 'DEPT_PK' showed EMP EMP_DEPT_FK DEPT_PK. We dropped that foreign key first with ALTER TABLE emp DROP CONSTRAINT emp_dept_fk, and then DROP PRIMARY KEY succeeded.

Setup
Setuprun as lab_a
CREATE TABLE dept (dept_id NUMBER CONSTRAINT dept_pk PRIMARY KEY, name VARCHAR2(30));
CREATE TABLE emp (emp_id NUMBER PRIMARY KEY, dept_id NUMBER CONSTRAINT emp_dept_fk REFERENCES dept);
INSERT INTO dept VALUES (10, 'SALES');
INSERT INTO emp VALUES (1, 10);
COMMIT;
OUTPUT
Table created.


Table created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
ALTER TABLE dept DROP PRIMARY KEY;
✕ ERROR
ALTER TABLE dept DROP PRIMARY KEY
*
ERROR at line 1:
ORA-02273: this unique/primary key is referenced by some foreign keys
Help: https://docs.oracle.com/error-help/db/ora-02273/
Checkrun as lab_a
COLUMN table_name FORMAT A10
COLUMN constraint_name FORMAT A12
COLUMN r_constraint_name FORMAT A10
SELECT table_name, constraint_name, r_constraint_name FROM user_constraints WHERE constraint_type = 'R' AND r_constraint_name = 'DEPT_PK';
OUTPUT
TABLE_NAME CONSTRAINT_N R_CONSTRAI
---------- ------------ ----------
EMP        EMP_DEPT_FK  DEPT_PK

1 row selected.
Fixrun as lab_a
ALTER TABLE emp DROP CONSTRAINT emp_dept_fk;
OUTPUT
Table altered.

Once the foreign key is gone, the child data is no longer checked. If you are rebuilding the key, add the foreign key back afterwards.

After the fixrun as lab_a
ALTER TABLE dept DROP PRIMARY KEY;
✓ SUCCESS
Table altered.

02A foreign key references a UNIQUE constraint, not the primary key

logins.email referenced users (email), which is covered by the UNIQUE constraint users_email_uk. Running ALTER TABLE users DROP CONSTRAINT users_email_uk failed with ORA-02273.

user_constraints with r_constraint_name = 'USERS_EMAIL_UK' showed LOGINS LOGINS_EMAIL_FK R. ALTER TABLE users DROP CONSTRAINT users_email_uk CASCADE succeeded, and LOGINS_EMAIL_FK was gone too (0 rows).

Setup
Setuprun as lab_a
CREATE TABLE users (user_id NUMBER PRIMARY KEY, email VARCHAR2(100) CONSTRAINT users_email_uk UNIQUE);
CREATE TABLE logins (login_id NUMBER PRIMARY KEY, email VARCHAR2(100) CONSTRAINT logins_email_fk REFERENCES users (email));
OUTPUT
Table created.


Table created.
Reproducerun as lab_a
ALTER TABLE users DROP CONSTRAINT users_email_uk;
✕ ERROR
ALTER TABLE users DROP CONSTRAINT users_email_uk
                                  *
ERROR at line 1:
ORA-02273: this unique/primary key is referenced by some foreign keys
Help: https://docs.oracle.com/error-help/db/ora-02273/
Checkrun as lab_a
COLUMN table_name FORMAT A10
COLUMN constraint_name FORMAT A16
SELECT table_name, constraint_name, constraint_type FROM user_constraints WHERE r_constraint_name = 'USERS_EMAIL_UK';
OUTPUT
TABLE_NAME CONSTRAINT_NAME  C
---------- ---------------- -
LOGINS     LOGINS_EMAIL_FK  R

1 row selected.

CASCADE drops every foreign key that references the constraint, without listing them. Check which ones they are before you use it.

After the fixrun as lab_a
ALTER TABLE users DROP CONSTRAINT users_email_uk CASCADE;
SELECT COUNT(*) AS fk_left FROM user_constraints WHERE constraint_name = 'LOGINS_EMAIL_FK';
✓ SUCCESS
Table altered.


   FK_LEFT
----------
         0

1 row selected.

03The foreign key is in another schema, so you cannot see it

lab_b.projects had CONSTRAINT projects_dept_fk REFERENCES lab_a.dept. As lab_a, user_constraints showed 0 foreign keys, yet ALTER TABLE dept DROP PRIMARY KEY failed with ORA-02273.

As a DBA, dba_constraints with r_owner = 'LAB_A' and r_constraint_name = 'DEPT_PK' showed LAB_B PROJECTS PROJECTS_DEPT_FK. After the owner lab_b dropped that foreign key, DROP PRIMARY KEY succeeded as lab_a.

Setup
Setuprun as lab_a
CREATE TABLE dept (dept_id NUMBER CONSTRAINT dept_pk PRIMARY KEY, name VARCHAR2(30));
GRANT REFERENCES ON dept TO lab_b;
OUTPUT
Table created.


Grant succeeded.
Setuprun as lab_b
CREATE TABLE projects (project_id NUMBER PRIMARY KEY, dept_id NUMBER CONSTRAINT projects_dept_fk REFERENCES lab_a.dept);
OUTPUT
Table created.
Reproducerun as lab_a
SELECT COUNT(*) AS my_fks FROM user_constraints WHERE constraint_type = 'R';
ALTER TABLE dept DROP PRIMARY KEY;
✕ ERROR
    MY_FKS
----------
         0

1 row selected.

ALTER TABLE dept DROP PRIMARY KEY
*
ERROR at line 1:
ORA-02273: this unique/primary key is referenced by some foreign keys
Help: https://docs.oracle.com/error-help/db/ora-02273/
Checkrun as system
COLUMN owner FORMAT A6
COLUMN table_name FORMAT A10
COLUMN constraint_name FORMAT A17
SELECT owner, table_name, constraint_name FROM dba_constraints WHERE constraint_type = 'R' AND r_owner = 'LAB_A' AND r_constraint_name = 'DEPT_PK';
OUTPUT
OWNER  TABLE_NAME CONSTRAINT_NAME
------ ---------- -----------------
LAB_B  PROJECTS   PROJECTS_DEPT_FK

1 row selected.
Fixrun as lab_b
ALTER TABLE projects DROP CONSTRAINT projects_dept_fk;
OUTPUT
Table altered.
After the fixrun as lab_a
ALTER TABLE dept DROP PRIMARY KEY;
✓ SUCCESS
Table altered.

FAQ

What does ORA-02273 mean?

A foreign key still references the primary key or unique constraint you are dropping. Drop or handle that foreign key first.

How do I find which foreign keys reference a primary key?

Query user_constraints with constraint_type = 'R' and r_constraint_name = 'PK_NAME'. For other schemas, use dba_constraints with r_owner too.

What does DROP CONSTRAINT ... CASCADE do?

It drops the constraint and every foreign key that references it. In our test the referencing FK no longer existed afterwards.

Why does ORA-02273 occur when user_constraints shows no foreign keys?

The foreign key can be in another user's schema. user_constraints shows only your own constraints; dba_constraints shows them all.

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