On a database I have Posts, Products and other tables.
Both posts and products can have comments with same structure.
create table dbo.Posts ( 
  Id int not null
  Title nvarchar (120) not null
)
create table dbo.Products ( 
  Id int not null
  Name nvarchar (120) not null
)
create table dbo.Comments ( 
  Id int not null
  Content nvarchar (2000) not null,
  Created datetime not null
)
create table dbo.PostComment ( 
  PostId int not null,
  CommentId int not null
)
create table dbo.ProductComment ( 
  ProductId int not null,
  CommentId int not null
)
I am using a common Comments table because all have the same columns.
Does this make sense? The other approach would be to have the following:
create table dbo.PostComments ( 
  Id int not null,
  PostId int not null,
  Content nvarchar (2000) not null,
  Created datetime not null
)
create table dbo.ProductComments ( 
  Id int not null,
  ProductId int not null,
  Content nvarchar (2000) not null,
  Created datetime not null
)
I have a few questions:
- Which approach makes more sense?
- On the first approach how can I guarantee that one Comment is only used on one Post ... And even better, would be used only in one Post or one Product?
 
    