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 6723225
In Process

The Archive Base Latest Questions

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

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

  • 0

Say I have two tables:

create table parent (
  id 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)
)

The parent table is big, say, 3 millions records. Now I run delete statement:

delete from parent; //even without where clause

Could you please explain what actually happens when this statement is executed? Where is no “ON DELETE CASCADE” option specified, as far as I understand it means that delete from parent table should fail if the child table contains references to parent id. So this means that before deleting the row from parent table Oracle should check if any child records exists. But this is really extremely slow – it’s row-by-row delete.

Am I correct? If not, please explain how Oracle works when deleting from parent table and check whether there are no orphans left in child table?

  • 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:32:39+00:00Added an answer on May 26, 2026 at 9:32 am

    Here’s a test. My PARENT table has 100000 rows. Against an empty CHILD table (with an index on PARENT_ID) deletion takes this long:

    SQL> set timing on
    SQL> delete from parent;
    
    100000 rows deleted.
    
    Elapsed: 00:00:07.24
    SQL> 
    

    Let’s insert some rows into CHILD. This will generate one row for every row in PARENT

    SQL> insert into child
      2  select level, level from dual
      3  connect by level <= 100000;
    
    
    100000 rows created.
    
    Elapsed: 00:00:02.21
    SQL> 
    

    If we delete from parent now, it fails instantly.

    SQL> delete from parent;
    delete from parent
    *
    ERROR at line 1:
    ORA-02292: integrity constraint (APC.CHILD_FK1) violated - child record found
    
    
    Elapsed: 00:00:00.14
    SQL> 
    

    Whereas, if we have every record in CHILD point to just one record in PARENT it takes a bit longer…

    SQL> update child set parent_id=99999;
    
    100000 rows updated.
    
    Elapsed: 00:00:09.65
    SQL> commit;
    
    SQL> delete from parent;
    delete from parent
    *
    ERROR at line 1:
    ORA-02292: integrity constraint (APC.CHILD_FK1) violated - child record found
    
    
    Elapsed: 00:00:07.32
    

    Wallclock timings are notoriously unreliable, but that looks like roughly the same amount of time. And as it happens, the time to delete the PARENT table without foreign key dependencies is in the same ballpark:

    SQL> drop table child;
    
    Table dropped.
    
    Elapsed: 00:00:02.29
    SQL> delete from parent;
    
    100000 rows deleted.
    
    Elapsed: 00:00:06.54
    SQL> 
    

    So, basically, there is little or no overhead to check the foreign key constraint

    There is a proviso: this is true providing the foreign key column is indexed. I dropped the CHILD_FK1_I index, and the delete from parent statement still hasn’t finished in the time it’s taken me to type up this response i.e. about ten minutes.

    • 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 ( number not null, constraint parent_pk
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.