OiO.lk Blog SQL What is the best way to handles comments related to multiple tables in SQL?
SQL

What is the best way to handles comments related to multiple tables in SQL?


I have a SQL structure that could be illustrated like so (simplified):
Parts, Variants, Machines, Persons. Each have different relations, e.g.;

  • 1 Part to many Variants
  • Many Parts to Many Machines
  • Many Persons to Many Parts

I need to be able to add comments to each entry in either one of these tables. So one Part/Variant/Machine/Person can have many comments. A comment entry always contains user_id, timestamp, comment_text

Should I just do a tables for each, e.g Part_Comments, Variant_Comments etc. Or could/should I make one table for all comments and include the table id somehow. So the columns would be something like: entry_id, table_id, user_id, timestamp, comment_text.

Is there a best practice for this?
Thanks



You need to sign in to view this answers

Exit mobile version