Error: ORA-02270: no matching unique or primary key for this column-list
Cause: You tried to reference a table using a unique or primary key, but
the columns that you listed did not match the primary key, or a primary
key does not exist for this table.
Action: The options to resolve this Oracle error are:
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 (supplier_id)
);
You would receive the following error message:
ORA-02270: no matching unique or primary key for this column-list
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);
Cause: You tried to reference a table using a unique or primary key, but
the columns that you listed did not match the primary key, or a primary
key does not exist for this table.
Action: The options to resolve this Oracle error are:
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 (supplier_id)
);
You would receive the following error message:
ORA-02270: no matching unique or primary key for this column-list
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);
文章標籤
全站熱搜
