How to update the foreign key table [message #610173] |
Tue, 18 March 2014 05:39 |
|
mist598
Messages: 1195 Registered: February 2013 Location: Hyderabad
|
Senior Member |
|
|
Hi all,
I want to update the foreign key table , But i am getting "ORA-02291: integrity constraint (APPS.FK_SUPPLIER_COMP) violated - parent key not found"
Is this value mandatory in the primary table(parent table)?
CREATE TABLE supplier
( supplier_id numeric(10) not null,
supplier_name varchar2(50) not null,
contact_name varchar2(50),
CONSTRAINT supplier_pk PRIMARY KEY (supplier_id)
);
CREATE TABLE products
( product_id numeric(10) not null,
supplier_id numeric(10),
supplier_name varchar2(50),
CONSTRAINT fk_supplier_comp
FOREIGN KEY (supplier_id)
REFERENCES supplier(supplier_id)
ON DELETE SET NULL
);
insert into supplier values(10,'rajesh','m')
insert into supplier values(20,'rajesh','m')
insert into products values(100,10,'m')
insert into products values(200,20,'m')
select * from supplier
select * from products
delete from supplier where SUPPLIER_ID=10
SQL> select * from products
2 /
PRODUCT_ID SUPPLIER_ID SUPPLIER_NAME
---------- ----------- --------------------
100 m
200 20 m
update products
set SUPPLIER_ID=40
where PRODUCT_ID=100
"ORA-02291: integrity constraint (APPS.FK_SUPPLIER_COMP) violated - parent key not found"
I want to update the SUPPLIER_ID with different value.
[Updated on: Tue, 18 March 2014 05:40] Report message to a moderator
|
|
|
|
Re: How to update the foreign key table [message #610175 is a reply to message #610174] |
Tue, 18 March 2014 05:49 |
|
mist598
Messages: 1195 Registered: February 2013 Location: Hyderabad
|
Senior Member |
|
|
Quote:No problem, as long as you first insert parent key 40 into the parent (supplier) table.
I want to update after SUPPLIER_ID column is NULL in the products Table.Means i have SUPPLIER_ID=10 from supplier right? Mean SUPPLIER_ID=10 is got the NULL Value in the products Table right? I want to update this column(NULL Column )with any value and i don't want to insert into the parent table
SQL> select * from supplier
2 /
SUPPLIER_ID SUPPLIER_NAME CONTACT_NAME
----------- -------------------------------------------------- ---------------------
20 siva m
SQL> select * from products
2 /
PRODUCT_ID SUPPLIER_ID SUPPLIER_NAME
---------- ----------- --------------------------------------------------
100 m
200 20 m
[Updated on: Tue, 18 March 2014 05:50] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|