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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:34:08+00:00 2026-05-12T18:34:08+00:00

Scenario I have 3 database tables. One is for Images and the other two

  • 0

Scenario

I have 3 database tables. One is for Images and the other two are People & Places. Since each person can have many images and each place can have many images, I want to have a ONE TO MANY Relationship between both people and images, as well as places and images.

Question

Does the foreign key have to be called the same name as the primary key? Or is it possible for me to call the Foreign key in the images table something generic, for example "PKTableID". This way I only need one image table.

Help greatly appreciated.

Regards,

EDIT:

The reason for wanting to have only a single image table, is because each image only refers to a single other table. As well as this, I used the example here of two tables, the actually database I will be using will have 20 tables, so I wanted to know whether it was still possible to use a SINGLE IMAGE TABLE FOR 20 ONE-TO-MANY RELATIONSHIPS?

  • 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-12T18:34:09+00:00Added an answer on May 12, 2026 at 6:34 pm

    EDIT

    If one image is only ever owned by one of the twenty tables, this design might work:

    People (PersonId, Name)
    Places (PlaceId, Name)
    Dogs (DogId, Breed)
    Doors (DoorId, Height, Width)
    Images (ImageId, ImageBinary, OwnerId, OwnerTable)
    

    Where OwnerTable is the name or the code for the table that OwnerId belongs to.

    This would save you 20 FKs in the image table, or 20 association tables. Then, in the joins, you would specify OwnerTable, depending on the table you are joining to.

    You would need to use convertable types for the Ids (eg, TINYINT, SMALLINT, and INT), and preferably one type for all (eg, INT), and you would have to manage referential integrity yourself though triggers or some other code.

    /EDIT

    You need 5 tables, not 3:

    People (PersonId, Name)
    Places (PlaceId, Name)
    Images (ImageId, ImageBinary)
    ImagesPeople (ImageId, PersonId)
    ImagesPlaces (ImageId, PlaceId)
    

    You can call the fields whatever you want. People.Id, ImagesPeople.PersonId, etc.

    But what you can’t do is something like this:

    People (PersonId, Name)
    Places (PlaceId, Name)
    Images (ImageId, ImageBinary, PlaceOrPersonId)
    

    Well, you can, but the database won’t help you enforce the relationship, or tell you which table the FK belongs to. How would you know? There are hackish work-arounds like staggering the id increments, adding a type column to Images, or using GUIDs.

    Alternatively:

    Things (ThingId PK, Type)
    People (ThingId PK/FK, Name, Age)
    Places (ThingId PK/FK, Name, LatLon)
    Images (ImageId PK, ImageBinary, ThingId FK)
    

    You could also make Images a “Thing”. Sometimes you see designs like this. It does give you referential integrity, but not type exclusivity. You could have the same ThingId in People, Places and Images, and the database wouldn’t care. You would have to code that rule yourself.

    Edit: at Cylon Cat’s suggestion, scenario 4:

    People (PersonId, Name)
    Places (PlaceId, Name)
    PeopleImages (PeopleImageId, ImageBinary)
    PlaceImages (PlaceImageId, ImageBinary)
    

    Here, images are exclusively owned by one person or place. Similar to version 2, but with declared foreign keys. It may have some performance benefits vs the 5 table design, since fewer joins are required. You lose “Image” as a distinct entity, replaced by “PeopleImage” and “PlaceImage”.

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

Sidebar

Related Questions

I have a scenario where I combine two tables into one (using UNION) and
I have a database of people and shirts. Each person has specific shirts that
Scenario. I have a library shelf, library, user, application tables in the database. One
Scenario I have an TWO datbase tables of exactly the SAME STRUCTURE. The difference
Consider the following scenario We have a simple database that involves two entities: user
I have two different database. One of them, original database and another one is
I've got a scenario where I have a database with one table that gets
One of the classical reasons we have a database deadlock is when two transactions
In the hypothetical scenario where I have a couple of database tables, in a
Say I have a database with two tables: food, and whatToEat. I query the

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.