Solved

How to perform Cascade Delete In Oracle database

Posted on 2007-03-28
6
45,216 Views
Last Modified: 2013-12-18
I am using Oracle 10.2.  How do I set up the relationship between parent table and child tables so that when
record is deleted from the parent table it should also delete all the records in the child tables.

Thank you
0
Comment
Question by:jyem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 42

Expert Comment

by:dqmq
ID: 18812170
0
 

Author Comment

by:jyem
ID: 18812521
I created a foreign key in the chilld table and link it to the pramary key in the parent table.  When deleting the record from the parent table I got the following error.

ORA-02292: integrity constraint (CBTM_OWN.CONSIST_DP_LOCO_R01) violated - child record found
0
 
LVL 3

Expert Comment

by:cdemir
ID: 18814043
could you send table scripts
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 13

Accepted Solution

by:
riazpk earned 500 total points
ID: 18814095
while declaring the Foreign key, you will have to mention ON DELETE CASCADE option:

SQL>create table parent(a number primary key);

Table created.

SQL>ed
Wrote file afiedt.buf
  1* create table childe(a number, b varchar2(10), constraint child_fk foreign key(a)references parent on delete cascade)
SQL>/

Table created.

SQL>insert into parent values(1);

1 row created.

SQL>ed
Wrote file afiedt.buf

  1* insert into childe values(1, 'ABC')
SQL>/

1 row created.

SQL>commit;

Commit complete.

SQL>delete parent;

1 row deleted.

SQL>commit;

Commit complete.

SQL>SELECT * FROM parent;

no rows selected

SQL>ed
Wrote file afiedt.buf

  1* SELECT * FROM childe
SQL>/

no rows selected

SQL>
0
 

Author Comment

by:jyem
ID: 18815491
Thank you very much everyone.  Riazpk solution works.
0
 

Expert Comment

by:Chip
ID: 22877881
Is there a script that can be run to identify what that one row will affect, if it is deleted?  I need to display all the tables that are dependant on that one record before deleting for documentation purposes.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question