Say you have multiple “things” which can each have one or more comments attached. Product and Order, for instance. How should the tables be structured….
- Product, Order, Comment, ProductComment { ProductID, CommentID }, OrderComment { OrderID, CommentID }
- Product, Order, ProductComment { ProductID, Text }, OrderComment { OrderID, Text }
- Product, Order, Comment { ProductID, OrderID, Text }
Using SQL Server 2008, by the way.
Thoughts, opinions?
Definitely only use one Comment table, so you don’t have to duplicate Comment information (e.g. timestamp, flagged_for_moderation, etc). Having two fields in comment is nice because it makes it clear that it’s a one-to-many link. I’d probably lean towards that over multiple linking tables, though I do appreciate that you only have rows in the linking table when there’s a link, versus having half the values be
NULL. Perhaps in a very large database with more things that can be commented, you might go for the linking tables.