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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:37:00+00:00 2026-05-24T01:37:00+00:00

This is probably a very stupid question, but I am just not sure which

  • 0

This is probably a very stupid question, but I am just not sure which solution is the most elegant and the best(most performant) way to go in the following scenario.

I have the following tables:

Customer, Company, Meter, Reading

all of the tables above the line are supposed to be linked to one or more records of a “Comment” table. Which is the best way to model this relationship?

I am seeing two solutions here:

1.) use m:n relationships: CustomerComment, CompanyComment, etc. -> easy to extend later on, but a lot of new tables
2.) use 1:n relationships: Comment table has a field for the PK of the tables above (Customer_id, Company_id, …) -> minimal table approach, but “harder” to extend since I would have to add a new field to the comment table whenever there is a new table that needs to be have comments

The target is a modular application, which may or may not have any of those four tables.

Which one is the better one – or are there more?

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-24T01:37:01+00:00Added an answer on May 24, 2026 at 1:37 am

    This is the problem with using integers for primary keys. You have a few solutions you can use.

    The true unique ID for any given row for Customer, Company, Meter, Reading is a UUID. Maybe because of the database design the primary key has to be an integer but that is ok. This means you never have to add fields to the COMMENTS table if you have a new type in your system. It will always reference by the types ID.

    Your tables can look like this:

    CUSTOMER
       ID UUID
    
    COMPANY
       ID UUID
    
    METER
       ID UUID
    
    COMMENTS
       ID
       RELATED_TO UUID
       COMMENT TEXT
    

    Now you can attach comments to any table that has a unique ID.

    If you want to support referential constraints

    OBJECT is a table that holds all of the ID’s of all the pieces of data you have in your system. We really start building a system in which you can associate any comment with anything you want. This may not be suitable in your design.

    OBJECT
       ID UUID 
    
    CUSTOMER
       ID UUID
       FOREIGN_KEY (ID) REFERENCES OBJECT(ID) ON DELETE CASCADE
    
    COMPANY
       ID UUID
       FOREIGN_KEY (ID) REFERENCES OBJECT(ID) ON DELETE CASCADE
    
    METER
       ID UUID
       FOREIGN_KEY (ID) REFERENCES OBJECT(ID) ON DELETE CASCADE
    
    COMMENTS
       ID
       RELATED_TO UUID
       COMMENT TEXT
       FOREIGN_KEY (RELATED_TO) REFERENCES OBJECT(ID) ON DELETE CASCADE
    

    This complicates the design in order to assure you don’t need to add 2 tables for each new type in the system. Each design has sacrifices. In this one you’ve complicated things by saying for every each entry whether it be Company, Customer, Meter I need an associated ID int he Object table so I can put a foreign key on it.

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

Sidebar

Related Questions

This is probably a very stupid question for SQL stalwarts, but I just want
This is probably a very stupid question. But assume that I have a DLL
I'm not too good with css so this is probably a stupid question but...
This is probably a very stupid math question, but i can't seem to figure
This is probably a very simple and stupid question to ask, but I have
This is probably a really stupid newbie-sounding question to you developer type people, but
This is probably a stupid question but my googling isn't finding a satisfactory answer.
this is probably a very stupid question; in a bash script, given the output
This is probably something very simple but I'm not getting the results I'm expecting.
This is probably a stupid question but I need to ask it because I've

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.