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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:30:36+00:00 2026-05-16T01:30:36+00:00

I have a situation where I have a table that has a soft foreign

  • 0

I have a situation where I have a table that has a soft foreign key to link records in the table to one of many other tables depending on another value in the table. To demonstrate:

TableOfTables: Id, TableName

HistoryTable: Id, TableOfTableId, NumberedTableId, etc…

Table1: Id, etc…

Table2: Id, etc…

Table3: Id, etc…

TableOfTables contains a record for each numbered table in the database (Table1, Table2, Table3, …). The HistoryTable has a foreign key to this table (TableOfTableId). It also has a column, NumberedTableId which is a reference to the Id column of the numbered tables.

Now, this works just fine, but there is no referential integrity between NumberedTableId and the Id columns of the numbered tables. Now as far as I am aware you cannot create a sort of conditional foreign key that can point at different tables depending on some condition…so what would be the best way to get referential integrity here?

The only two things I can think of are to have lots of nullable NumberedTableId columns in the HistoryTable, each one with a foreign key to a specific numbered table with the rest of the columns filled with nulls…ugly, or to have a seperate HistoryTable for each numbered table…this will mean lots of HistoryTables as there are many numbered tables in our database.

What is my best option here? History table is really a logging table that records changes and who changed values in the numbered tables, its not used for anything other than auditing and not read at all by our program, but I don’t like not having total referential integrity.

What are my options here? Any solution needs to be able to work with Entity Framework 4.0.

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. Editorial Team
    Editorial Team
    2026-05-16T01:30:37+00:00Added an answer on May 16, 2026 at 1:30 am

    Actually, there are three options (you have mentioned two but I’ll restate them here)

    1. Multiple FK columns with a check constraint to enforce that a given row can only have a single FK value.
    2. Multiple history tables
    3. A single history table with a triggers from hell to enforce referential integrity (triggers on the source tables and the history table).

    There is no clean answer. My approach to this problem has been to have a history table for each table of current data with a foreign key and cascade update and delete. This at least avoids a bottleneck on a single table, allows for referential integrity and is clear to other developers.

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

Sidebar

Related Questions

Here is my situation: I have one table that contains a list of drugs
I have Object1 and junction table and Object2. Object2 is table that has many
I have a situation that I cannot change: one database table (table A) accepts
My ideal situation would be to have a table that, in production (Oracle) has
I have the following situation: An Conversations entity/table which has multiple Tags associated to
Strange situation. If I have these tables: CREATE TABLE t1 (id INT, title VARCHAR(20),
I have a table named Orders that has a column named OrderCode that stores
I have a MySQL database table that has a VARCHAR field storing a date
The situation is as follows: I have a ViewModel that has a property that's
I have a situation. How can I extract AppId that has only taken C++.

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.