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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:22:57+00:00 2026-05-11T11:22:57+00:00

I am trying to figure out if it is possible to create a foreign

  • 0

I am trying to figure out if it is possible to create a foreign key in this way.

First there are two parent tables in this scenario.

Table 1 has a PK int and another int column. When combined the two are unique.

Table 2 has a PK int and another int column. When combined the two are unique.

The paired value between the two ints is how we currently select the child records for either table.

Table 3 has a value for the PK and other int column from one of the first two tables. It is reliably selectable because the two fields when both used in a search are unique to one of the above tables.

So I am looking to create a FK or possibly two FK for this scenario. I would like to be able to do cascading deletes from either of the first tables into the third table, and would also like to use this for the entity relationships in Entity Framework.

Please let me know if this is not making sense. I have read it several times, and it is about as clear as I can get it.

Thanks

  • 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-11T11:22:57+00:00Added an answer on May 11, 2026 at 11:22 am

    If Table3 contains all values in Table1 UNION Table2, then you have an inheritance scheme:

    Table3 { (int id, int type) PK } Table1 { (int id, int type [CHECK type = 1]) FK Table3 } Table2 { (int id, int type [CHECK type = 2]) FK Table3 } 

    With that, deleting from Table3 will cascade to Table1 or Table2 appropriately.

    Otherwise, if Table3 is just a subset of Table1 UNION Table2 – then introducing Table4 as the full set would work.

    Table4 { (int id, int type [CHECK type IN (1,2)]) PK } Table1 { (int id, int type [CHECK type = 1]) FK Table4 } Table2 { (int id, int type [CHECK type = 2]) FK Table4 } Table3 { (int id, int type) FK Table4 } 

    To handle cascaded deletes, though, you’d need to delete from Table4 (though you could do a trigger on Table3 to handle that for you).

    Edit (because I think it’s an important point that should be seen, seperate from the comments):

    Yeah, the problem with this is that one and two are the parents. They both have related records in 3, which would be a FK, not a PK for that table. It seems to be pretty much impossible using a FK constraint. Thanks for the response! – Chrisb (an hour ago)

    IMO – your data model is broken then. Table1 and Table2 are unrelated, but you’re trying to stuff them into the same column in Table3. If Table1 and Table2 are related somehow, then you need to model that.

    Either introduce a parent table (Table4) if they’re related, or either a 2nd column in Table3 (Table1 FK, Table2 FK) or 2 join tables if they’re not. Don’t try to put a round peg into a square hole – and don’t try to make up for it with a trigger. 😉

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

Sidebar

Related Questions

No related questions found

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.