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 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

Related Questions

I found from this link that there are several types of XML parsers in
I have to serialize several objects inheriting from WebControl for database storage. These include
I am working on a client / server system: There is a database, an
There are several threads on this here at SO but I didn't find one
There are several other questions about this topic that I have gone through, but
There are several variant questions on this on SO, but I did not find
There are several places on the internet that talk about having multy key dictionary
There are several ways google throws at me for checking if a file is
There are several good Javascript editors for Markdown / Textile (e.g.: http://attacklab.net/showdown/ , the
There are several resources out there that explain how the sandbox in Chrome works

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.