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

  • Home
  • SEARCH
  • 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 31975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:41:22+00:00 2026-05-10T13:41:22+00:00

There are several types of objects in a system, and each has it’s own

  • 0

There are several types of objects in a system, and each has it’s own table in the database. A user should be able to comment on any of them. How would you design the comments table(s)? I can think of a few options:

  1. One comments table, with a FK column for each object type (ObjectAID, ObjectBID, etc)
  2. Several comments tables, one for each object type (ObjectAComments, ObjectBComments, etc)
  3. One generic FK (ParentObjectID) with another column to indicate the type (‘ObjectA’)

Which would you choose? Is there a better method I’m not thinking of?

  • 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-10T13:41:22+00:00Added an answer on May 10, 2026 at 1:41 pm

    @palmsey

    Pretty much, but the variation on that pattern that I’ve seen most often gets rid of ObjectAID et al. ParentID becomes both the PK and the FK to Parents. That gets you something like:

    • Parents

      • ParentID
    • ObjectA

      • ParentID (FK and PK)
      • ColumnFromA NOT NULL
    • ObjectB

      • ParentID (FK and PK)
      • ColumnFromB NOT NULL

    Comments would remain the same. Then you just need to constrain ID generation so that you don’t accidentally wind up with an ObjectA row and an ObjectB row that both point to the same Parents row; the easiest way to do that is to use the same sequence (or whatever) that you’re using for Parents for ObjectA and ObjectB.

    You also see a lot of schemas with something like:

    • Parents
      • ID
      • SubclassDiscriminator
      • ColumnFromA (nullable)
      • ColumnFromB (nullable)

    and Comments would remain unchanged. But now you can’t enforce all of your business constraints (the subclasses’ properties are all nullable) without writing triggers or doing it at a different layer.

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

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer yes, you can assign sys.stdout to whatever you want. Create… May 11, 2026 at 11:09 am
  • added an answer You could use a BackgroundWorker and then change the UI… May 11, 2026 at 11:09 am
  • added an answer you could create a GUID and save the image as… May 11, 2026 at 11:09 am

Related Questions

There are several types of objects in a system, and each has it's own
There are several ways to iterate over a result set. What are the tradeoff
There are several plugin options for building a search engine into your Ruby on
There are several web applications which allow you to send photos from your mobile
There are several different methods for converting floating point numbers to Integers in JavaScript.
There are several people about (myself being one of them) who have been developing
There are several similar Oracle technologies - Oracle Streams, Oracle Change Data Capture and
There are several topics about what questions will be raised in an interview for
There are several ways to do this, but I'm not sure which one of
There are several filter methods for dates (year,month,day). If I want to match a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.