7 Replies Latest reply: Dec 7, 2012 6:04 AM by 930854 RSS

    cascade

    930854
      Hi ,

      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
      found


      how to delete the parent table value without deleting the child value
        • 1. Re: cascade
          523861
          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.
          • 2. Re: cascade
            sb92075
            927851 wrote:
            Hi ,

            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
            found


            how to delete the parent table value without deleting the child value
            you can not delete parent when child still exists.
            • 3. Re: cascade
              908002
              if you dont want to delete the child record .. update it to null

              or create foriegn key constraint on delete set null.
              • 4. Re: cascade
                971895
                drop the index on table then create as DELETE CASCADE

                Example:

                ALTER TABLE emp ADD CONSTRAINT R_1 FOREIGN KEY (deptno) REFERENCES dept(deptno) ON DELETE CASCADE
                • 5. Re: cascade
                  vijayrsehgal-Oracle
                  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
                  • 6. Re: cascade
                    930854
                    HI,
                    Sorry for the late reply. Its working fine now. thanks for the update.
                    • 7. Re: cascade
                      930854
                      thanks for update