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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:51:32+00:00 2026-06-18T00:51:32+00:00

I will explain my case with an example. I have the following tables: persons

  • 0

I will explain my case with an example.

I have the following tables: persons, places, pictures. Both persons and places have many pictures. What is the best way to express this in a database scheme while maintaining referential integrity?

  1. I could add a column for each possible association, but this will create a lot of empty fields when there are other things that have pictures, too.
  2. I could create association tables between persons and pictures and places and pictures. But then the foreign keys would be in the association table and I cannot enforce that pictuers are deleted when places etc. are deleted.

At the moment I lean towards the second approach, but I do not like it.

  • 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-06-18T00:51:33+00:00Added an answer on June 18, 2026 at 12:51 am

    There’s no one-size fits all solution that will tick all of the boxes you want. But one I’ve seen before is

    3) Introduce a base table for items that will share relationships:

    CREATE TABLE Entities (
        EntityID int not null primary key,
        EntityType varchar(10) not null,
        constraint CK_EntityTypes CHECK (EntityType in ('Person','Place')),
        constraint UQ_Entities_WithTypes UNIQUE (EntityID,EntityType)
    )
    

    And then build your People and Places tables:

    CREATE TABLE People (
        PersonID int not null PRIMARY KEY,
        EntityType AS CAST('Person' as varchar(10)) persisted,
        ...Other columns...
        constraint FK_People_Entities FOREIGN KEY (PersonID,EntityType) references Entities (EntityID,EntityType)
    )
    
    CREATE TABLE Places (
        PlaceID int not null PRIMARY KEY,
        EntityType AS CAST('Place' as varchar(10)) persisted,
        ...Other columns...
        constraint FK_Places_Entities FOREIGN KEY (PlaceID,EntityType) references Entities (EntityID,EntityType)
    )
    

    (I’m not sure Entities is exactly right when thinking about places – a better name may suggest itself to you).

    You can then have Pictures just references the EntityID.


    Otherwise, if I had to pick between 1 & 2, I’d usually recommend 1. Unless the number of “types” involved gets large, it still doesn’t make the Pictures table too wide, and as you’ve observed, you can at least use the normal FK mechanisms to enforce cascades, if necessary.


    4) If Pictures is just a very bare table at the moment, maybe query whether there ought to be one pictures table, or one per type. Will pictures of people and pictures of places frequently end up queried together (and even if they are, could a UNION ALL based query hide the fact that you’re using separate tables)?

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

Sidebar

Related Questions

The title is a little confusing so I will explain. I have the following
I have many custom classes that I am using that I will explain and
I have problem adding arraylist to list view, will explain about my problem here..
I am trying to reduce some code here. I will explain how I have
I want to use regular expression same way as string.Format. I will explain I
Please definitively explain what the method resolution rules are in the following case. I
The question is a bit complicated so I will try and explain. I have
I have huge data matrices stored in a MATLAB M-file and I will explain
This is hard to explain, but I will do my best: I am building
my problem is easy to explain with an example: I have a 'common' schema

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.