Search code examples
database-designnormalization

Comment system on website


Given a comments system for elements on my pages, I want to avoid repeating tables, like:

tblBlogComments
tblNewsComments
tblArticleComments

etc etc

What's a good way to design this? One comments table? How do I link those to single entires in the blog?


Solution

  • Sure you could use a single table for these, but you have to consider very carefully if you might ever want to add specific functionality / fields for a particular table which you don't want for the others.

    i.e. you could have

    TABLE Comments (commentid, userid, blogid, newsid, articleid, commenttitle, comment)
    

    But if you then want to add another field for News comments only i.e. NewsPicture then there's a fine line between making things easier for you and ending up with a table structure which is semantically incorrect