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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:43:08+00:00 2026-05-10T21:43:08+00:00

I’m working on a database that tracks files and dependencies in projects. Briefly, I

  • 0

I’m working on a database that tracks files and dependencies in projects. Briefly, I have two main tables; the PROJECTS table lists project names and other properties, the FILES table lists files. Every file entry points to a project as a foreign key set to CASCADE, so if I delete a project record from the database, all the file records disappear as well. So far, so good.

Now I have an additional DEPENDENCIES table. Each record in the dependency table is two files, specifying that the first file depends on the second. Again these are foreign keys, the first is set to CASCADE (so if I delete a file entry, this record is deleted), but the second is set to RESTRICT (so I am not allowed to delete a file entry if any other files depend on it). Again, everything seems good.

Unfortunately it seems I can no longer delete a project with a single SQL delete statement! The delete tries to cascade-delete the files, but if any of these appear in the DEPENDENCIES table, the RESTRICT foreign key prevents the delete (even though that record in the dependencies table will be removed because the other column is CASCADE). The only workaround I have is to calculate an exact order to delete the files so none of the dependency record constraints are violated, and remove the file records one at a time before attempting to remove the project.

Is there any way to set up my database schema so a single SQL delete from the projects table will correctly cascade the other deletes? I’m using Firebird 2.1, but I don’t know if that makes any difference – it seems like there ought to be a way to make this work?

  • 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. 2026-05-10T21:43:09+00:00Added an answer on May 10, 2026 at 9:43 pm

    You can’t control the order of deletion through a cascading foreign key, but you may be able to design a trigger on PROJECTS to delete rows in FILES that belong to this project and are also listed in DEPENDENCIES as dependent on other FILES. Make it a BEFORE DELETE trigger, so it should execute before the cascading effects.

    Something like this:

    CREATE TRIGGER Del_Child_Files FOR PROJECTS BEFORE INSERT AS BEGIN   FOR SELECT F.FILE_ID FROM FILES F JOIN DEPENDENCIES D        ON F.FILE_ID = D.CHILD_ID     WHERE F.PROJECT_ID = OLD.PROJECT_ID     INTO :file_id   DO     DELETE FROM FILES WHERE FILE_ID = :file_id;   DONE END 

    So when you delete a project, this deletes all the ‘child’ files of a project that are dependent on other files, and this cascades to delete rows in DEPENDENCIES so all the remaining files are free of dependencies. Your deletion of the project can now cascade to delete these files.

    I haven’t tested this and my Firebird syntax may be rusty, but perhaps it’ll get you started.

    Obviously, please test this on a copy of your data, not the live data!

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

Sidebar

Ask A Question

Stats

  • Questions 300k
  • Answers 300k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, in general boost binary serialization is not machine-independent. See… May 13, 2026 at 7:53 pm
  • Editorial Team
    Editorial Team added an answer use CSS to apply margin between the two tables: <style… May 13, 2026 at 7:53 pm
  • Editorial Team
    Editorial Team added an answer ASP.NET authentication is designed to be resilient to an IISReset… May 13, 2026 at 7:53 pm

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.