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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:11:14+00:00 2026-05-23T01:11:14+00:00

I have a database with tables that are chained together with foreign keys, and

  • 0

I have a database with tables that are chained together with foreign keys, and the last one in the chain also has a foreign key to itself. I want to delete them with cascade on, exapt for the last one in the chain. That one should be set null, unless it’s parent record has a certain value. I figured i would do that with a trigger: whenever the last table updated, if the foreign key to itself had been set to null, check the field in the parent record, and if it is the value “default”, delete the record in the last table.

However, I haven’t found any help online indicting that comparing a parent record in another table.

Is this possible?

  • 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-23T01:11:15+00:00Added an answer on May 23, 2026 at 1:11 am

    AFAIK you won’t be able to really delete the record in the last table (mutating table problem), but you could update a status field indicating the record has been logically deleted (untested):

    create or replace trigger last_table_trig
    before update on last_table
    for each row
    declare
      l_parentField varchar2(100);
    begin
      if :new.self_ref_fk is null then
         select p.parent_field into l_parentField from parent_table p
         where p.pk = :new.parent_fk;
         if l_parentField = 'default' then
           :new.status := 'DELETED';
         end if;
      end if;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relatively large database tables (just under a million rows) that has
In my database, I have a few columns in one of my tables that
I have a database that has node & nodetype tables. Nodes table NodeID ParentNodeID
I have an Access database that has two tables that are related by PK/FK.
We have a database, that through a hiccup in a script, has one table
I have a database labor which contains the tables that the rails application has
I have two database tables. One table stores data for a commitment that a
I have a database structure that has two one-to-many relationships. I have a website,
I have a database that has two tables locations and classes. I am familiar
I have several database tables that just contain a single column and very few

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.