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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:04:36+00:00 2026-05-13T18:04:36+00:00

I have a parent/child relationship defined which, unfortunately, cannot be maintained via a foreign

  • 0

I have a parent/child relationship defined which, unfortunately, cannot be maintained via a foreign key. Parents and children are stored in the same table. The parent/child relationship is identified by a column “ITEM_ID”. A child ITEM_ID consists of its parent ITEM_ID and then what we can effectively think of as the child’s unique identifier within that parent item.

I’m implementing a PL/SQL procedure to delete records from this ITEM table. The first part of the procedure checks for the existence of any children; if so, it raises an application error (simulating a foreign key).

I’m wondering how to prevent child records from being inserted by another process between the time the cursor in my delete procedure is populated and locked “FOR UPDATE”, and the point at which the parent record is actually deleted.

Do I need to lock this entire table during this process?

Or should I alter the insert procedure to select the parent record “FOR UPDATE”?

UPDATE: I created the example above just to describe the general situation, but to justify my foreign key/constraint issue I’ll give my actual/more complicated structure below:

There are several tables in a remote database: COMPANY, BUILDING, FLOOR. In our organization, Floors belong to buildings and Buildings belong to Companies.

The application I’m working on associates roles with employees. The table that ties an Employee (Employee ID) with a Role (Role ID) also has a “Location” column. The location column corresponds to an ID one of the remote database tables, and we identify which table it belongs to based on the Type column in the Role table.

For example, here are a couple records from my table:

Role = Janitor
Type = BUILDING
Location = COMPANY1-BUILDING1
Parent Role = Manager


Role = Manager
Type = COMPANY
Location = COMPANY1
Parent Role = CEO

As you can guess, Floor identifiers have a format of company-building-floor in the remote database table.

Janitor is tied to the BUILDING level, and as such its Location column is a BUILDING identifier (which is actually the company identifier followed by a building identifier in the BUILDING 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-13T18:04:37+00:00Added an answer on May 13, 2026 at 6:04 pm

    Having the deleting process get a plain lock on the parent record won’t prevent child records being inserted. Locking the entire table would seriously serialize your application.

    So forcing the inserting process to SELECT … FOR UPDATE on the parent record and the deleting process to lock the parent record is your only option. The main problem with this implemntation is that it is so easy to circumevent. Or to put it another way, every process which interacts with the table is going to have to issue these additional locks.

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

Sidebar

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.