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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:29:51+00:00 2026-05-17T17:29:51+00:00

On a project I’m working on we’ve got some tables with numerous foreign key

  • 0

On a project I’m working on we’ve got some tables with numerous foreign key relationships, and because it’s in early development the number of relationships will likely change.

We’d like to be able to delete records from certain tables but are reluctant to set up cascading deletes on the foreign key relationships.

We’ve considered the following options:

  1. Ignore our instincts and set up cascading deletes anyway
  2. Instead of a cascading delete use set null
  3. Write and maintain a custom script to delete all the foreign key records manually

None of these options are great 🙁

  1. We don’t want to set up cascading deletes because we don’t want that to be the default behaviour.
  2. We don’t want to use cascading nulls becuase leaving lots of orphans would be useless.
  3. Writing a custom script would work, but it’s not very scalable or maintainable. Writing a script for a single table or even a few tables is ok, but for every table? Seriously? There must be a better way! At least I hope there’s a better way.

For the “Too Long Didn’t Read” crowd; A quick summary

Is there a way of specifying that you’d like a delete to cascade, on a query by query basis?

Perhaps something that looks like this:

-- wouldn't it be nice if this was a real command!
CASCADE DELETE FROM MyTable WHERE ID = @ID
  • 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-17T17:29:52+00:00Added an answer on May 17, 2026 at 5:29 pm

    I am not sure I really see the usefulness of manual cascade option in your case.
    The CASCADE is there to maintain certain relationships between entities and if you, and I quote,

    don’t want it to be default behaviour

    that then you can still:

    • issue multiple queries that will do your clean-up ‘manually’
    • use stored procedures if you want to do it with a single call, for example you might then have CALL CASCADE_DELETE('table_name', 'id = 3') (and you get a single point where you would maintain your clean-up scripts)
    • use triggers if you want to be fancy (for example you could create simple views on the original tables where deleting from these views would cascade – through instead triggers, and deleting from original tables would not cascade)

    But, please note that basically you are increasing complexity of the system because of what might be simply unfinished system design. That will not really help you in the long run and the design decisions should be addressed before hacking the functionality (if at all possible).

    EDIT:
    If the purpose is to clean test data to conform to the actual integrity rules then you could create a proper tables with proper rules and then move the data from test data tables to proper tables.
    Rows that don’t conform to the proper integrity will fail the insert and you will have the clean data.

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

Sidebar

Related Questions

Project Lombok makes it trivial to implement the boilerplate code in the classes. Is
project type is MVC2. Let say that i have page1. after success it write
project: Using VB.NET to build a winforms database interface and work-automation app. I am
project: Using VB.NET to build a winforms database interface and work-automation app. I am
Project : Game in Flex builder 4 (Actionscript Project) Language : Actionscript 3 This
Project type: Asp MVC 2/NHibernate/C# Problem If you have an edit page in an
Project A - Web Application/Website Project B - Unit Test Application I'm familiar how
Project (id) Permission (project_id, user_id) When user's create a project, I want to ensure
I have a bunch of posts stored in text files formatted in yaml/textile (from
[project_select] UserID (fk) | project_id (fk) | project_category_id (fk) [project_category] project_category_id | category [projects]

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.