totn Oracle Error Messages

Oracle / PLSQL: ORA-02268 Error Message

Learn the cause and how to resolve the ORA-02268 error message in Oracle.

Description

When you encounter an ORA-02268 error, the following error message will appear:

  • ORA-02268: referenced table does not have a primary key

Cause

You tried to reference a table using a unique or primary key.

Resolution

The option(s) to resolve this Oracle error are:

Option #1

This error commonly occurs when you try to create a foreign key that references a table that doesn't have a primary key. To resolve this problem, create a primary key on the referenced table. Then re-execute your command to create the foreign key.

For example, if you had tried to execute the following commands.

CREATE TABLE supplier
( supplier_id numeric(10) not null,
  supplier_name varchar2(50) not null,
  contact_name varchar2(50)
);

CREATE TABLE products
( product_id numeric(10) not null,
  supplier_id numeric(10) not null,
  CONSTRAINT fk_supplier
    FOREIGN KEY (supplier_id)
    REFERENCES supplier
);

You would receive the following error message:

Oracle PLSQL

Since there is no primary key on the supplier table, you can not create a foreign key on the products table that references the supplier table.

You can correct this error by adding a primary key to the supplier table as follows and then re-execute the CREATE TABLE statement for the products table:

ALTER TABLE supplier
 ADD CONSTRAINT supplier_pk PRIMARY KEY (supplier_id);