InsaneCoder
InsaneCoder

Reputation: 8288

Need help in database design for a comment page

I have a lot of questions on my website and corresponding to each question I have a link "Discuss in forum" which directs him to comments page for that question where the user can write his doubt and other users can also comment on that page to help him.

Now I couldn't figure out how to design database for that comments table and how to link that table to my question table(which has three columns :id,question,answer).

I need to store following things:

  1. All comments

  2. Name of the person who made that comment and votes that comment has received.

Upvotes: 0

Views: 72

Answers (1)

nestedloop
nestedloop

Reputation: 2656

Well, first off, a comment will relate to one question, and a question will have many comments. So you need an IdQuestion FK in the Comments table.

A comment can also be a reply to another comment, so another FK IdParentComment (from the PK IdComment).

Another FK for the poster (say IdUser).

To summarize:

Comments table:

IdComment (PK)

IdQuestion (FK from Questions.IdQuestion)

IdUser (FK from Users.IdUser)

IdParrentComment (FK from Comments.IdComment)

Text

VoteCount

Of course, this is just an example. You might want to know who voted for which comment. You'd then need a table Votes with IdVote, IdUser, IdComment.

Upvotes: 2

Related Questions