×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Delete child records before I can delete the parent

Delete child records before I can delete the parent

Delete child records before I can delete the parent

(OP)
Hello,

I'm a newbie to SQL and if it is not to difficult I can succeed to write querie's. I don't much know about PL/SQL. We are working with Oracle.

The parent ERD is this.

Table 1 --> linking Table --> Table 2 --> Table 3(detail)
1 |    1   1            1   1       1   n
  |--> Table 1 detail
    1

Now I want to delete for every record of table 1 who doesn't have record in the table 1 detail table, delete these records.
But before I can do this I have to delete the one or more records in table 3, then in table 2 and then the records in the linking table and at last the records from Table 1.

Can anybody help or put me in a direction how to solve this?
Cascade doesn't work I think.
Linking table is I mean a table with only three UID's(Table 1, Table 3 and his self)
I mean by the numbers the relation between the tables.

Thanks in advance,

Nico

RE: Delete child records before I can delete the parent

i think you would have a much better chance of getting a satisfactory reply if you posted this in one of the oracle forums

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon

RE: Delete child records before I can delete the parent

nkamp,

cascade delete on your foreign keys would certainly do the job, but I don't use cascade, as it means that something happens unexpectedly, behind the scenes.

The way to do it is to select from 3 inner join 2 inner join 1 using the FK fields, and then delete from that selection.  You have to start with the grandchildren, then delete the children, to finally make it possible to delete the parent record.

Regards

T

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close