This content has been marked as final. Show 7 replies
if you mean you'd like the child records deleted automatically, then you'll have to recreate the foreign key with the cascade delete option.
927851 wrote:you can not delete parent when child still exists.
Am using two tables called e1 and e2. In e2 table is having foriegn key which is reffering foriegn key of table e2. am deleting the records in parent table i got the below exception.
Please help me.
I got this exception
delete from e1where id=3005
ERROR at line 1:
ORA-02292: integrity constraint (e2.fkk_FK2) violated - child record
how to delete the parent table value without deleting the child value
if you dont want to delete the child record .. update it to null
or create foriegn key constraint on delete set null.
drop the index on table then create as DELETE CASCADE
ALTER TABLE emp ADD CONSTRAINT R_1 FOREIGN KEY (deptno) REFERENCES dept(deptno) ON DELETE CASCADE
read the manuals or some book, here's an e.g. for you.
create table e1(id number not null) create unique index idx_e1 on e1(id) alter table e1 add constraint pk_e1 primary key(id) create table e2(id_e2 number,id_e1 number) alter table e2 add constraint fk_e2 foreign key(id_e1) references e1(id) on delete cascade insert into e1 values(1) insert into e2 values(1,1) insert into e2 values(2,1) insert into e2 values(3,1) commit; delete from e1 where id=1
Sorry for the late reply. Its working fine now. thanks for the update.
thanks for update