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

  • Home
  • SEARCH
  • 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 5963421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:15:03+00:00 2026-05-22T19:15:03+00:00

I have a table that stores trees. There is a node_id and parent_id. When

  • 0

I have a table that stores trees. There is a node_id and parent_id.

When I try the following:

insert into table1 select * from table2 start with node_id = 1 connect by prior node_id = parent_id order by parent_id nulls first

I get this error:

Error starting at line 6 in command:
insert into table1 select * from table2 start with node_id = 1 connect by prior node_id = parent_id order by parent_id nulls first
Error report:
SQL Error: ORA-02291: integrity constraint (XVTEST.REGIONAL_DEFAULT_DELETE) violated - parent key not found
02291. 00000 - "integrity constraint (%s.%s) violated - parent key not found"
*Cause:    A foreign key value has no matching primary key value.
*Action:   Delete the foreign key or add a matching primary key.

I understand why I am getting this error. I was just wondering if there was a way to do this with out making a recursive pl/sql procedure. Thoughts? If it is not possible does anyone have a procedure that like this that I could use as a sample?

  • 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-22T19:15:04+00:00Added an answer on May 22, 2026 at 7:15 pm

    One option is to create the FOREIGN KEY constraints as DEFERRABLE, and then set them DEFERRED for your transaction, so the enforcement of the foreign key constraints is deferred until the COMMIT.

    Note that you don’t want to perform any SELECT while the contents of the tables violate the constraints. In some cases, some SELECT statements will return unexpected or inconsistent results. (Be sure to consider SELECT statements performed by triggers.)


    -- to create foreign key constraints as deferrable
    ALTER TABLE my_table ADD CONSTRAINT my_table_fk1 
    FOREIGN KEY (other_table_id) REFERENCES other_table (id)
    DEFERRABLE INITIALLY IMMEDIATE;
    
    -- defer all deferrable constraints until the next commit
    ALTER SESSION SET CONSTRAINTS=DEFERRED;
    -- or
    SET CONSTRAINTS ALL DEFERRED;
    
    -- dml operations may now temporarily violate constraints
    INSERT ... ; 
    UPDATE ... ;
    
    -- you can check the constraints before the commit
    SET CONSTRAINTS ALL IMMEDIATE;
    
    -- all deferred constraints will be enforced at the next commit
    -- (a fk violation exception will be raised here, rather than by the DML)
    COMMIT;
    

    Some helpful references:

    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:914629004506

    http://download.oracle.com/docs/cd/B10500_01/server.920/a96524/c22integ.htm#4666


    ADDENDA:

    This approach applies specifically to Oracle database, and may not be applicable to other relational database engines.

    The warning against performing SELECTS against the tables while the constraints are deferred applies only to the session that defers constraints. Other session will see a consistent state, since they will not see any uncommitted changes.

    Using DEFERRED constraints is preferred over disabling and re-enabling the constraints, since disabling constraints would affect all sessions, and re-validating the constraints can consume significant resources (for large tables).

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

Sidebar

Related Questions

I have the following xml that stores table definations. How can I loop through
I have one table that stores values with a point in time: CREATE TABLE
I have a SQL Server table with one column that stores Canadian Postal Codes.
I have a SQL Server 2008 R2 table with nvarchar(4000) field. Data that stores
We have a VOIP server that stores wav files for call recordings. My intention
I have a set of data that's organized hierarchically that should be able to
I have a problem with a mapping for this structure that i designed public
I'm importing Oracle data into SQL Server. After my OLE DB Source that runs
In SQL Server 2005, I have a query that involves a bunch of large-ish
I am working with Django for a while and now that my tree and

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.