Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6724851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:44:17+00:00 2026-05-26T09:44:17+00:00

Say I have two tables: create table parent ( number not null, constraint parent_pk

  • 0

Say I have two tables:

create table parent (
  number not null,
  constraint parent_pk primary key(id),
)

create table child (
  id number not null,
  parent_id number not null,
  constraint child_pk primary key(id),
  constraint child_fk1 foreign key(parent_id)
  references parent(id)
)

I’ve heard about bottom-up delete method. Something like this:

DELETE FROM child where parent_id IN (SELECT id FROM parent WHERE ...);
DELETE FROM parent WHERE ...;

I’ve also seen the following version:

DELETE FROM child c where exists (SELECT 1 FROM parent p WHERE c.parent_id=p.id AND ...);
DELETE FROM parent WHERE ...;

There are also exist ON DELETE CASCADE option. Could you please compare the performance of the mentioned ways?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:44:18+00:00Added an answer on May 26, 2026 at 9:44 am

    As you are interested in the algorithm, what your question seems to boil down to is the difference between IN and EXISTS as your two examples are the same save for the IN changing to an EXISTS in the delete from the CHILD table.

    There has been quite a lot written about this difference over the years but in essence IN is generally used where the number of comparators is small whereas EXISTS is more efficient for subqueries returning a larger number of comparators (especially if those values contain a large number of duplicates).

    IN has to evaluate every returned comparator while EXISTS is satisfied when it encounters the first match.

    There are exceptions to this and if you google for them then you will find them but on the whole this seems to hold true.

    Tom Kyte (Oracle VP) has a very good answer with explanations here:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:2148775836129778::::P11_QUESTION_ID:953229842074

    TechRepublic also has a good explanation here:
    http://www.techrepublic.com/article/oracle-tip-understand-the-difference-between-in-and-exists-in-subqueries/5297080

    Hope this helps…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have two tables: create table parent ( id number not null, constraint
Lets say I have these two tables: CREATE TABLE nodes ( id INTEGER PRIMARY
Lets say I have two tables - child and parent with many-to-one relation. What
Scenario: Let's say I have two tables, TableA and TableB. TableB's primary key is
Say I have two tables, user and comment . They have table definitions that
Let's say I have two Databases like so : DatabaseA create table Table1 (
Let's say I have two tables in a database: projects and users. I create
Say I have two tables I want to join. Categories: id name ---------- 1
Say we have two tables in an MS Access db: Service Users: | ID
Say I have two tables called A (fields: id, phase, name) and B(fields: id,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.