Take the 2-minute tour ×

Suppose there is a table called "content" where each row signifies a unique content for my website.

Now, I want to add a "comment" section to each unique content or you can say each row of the table. Currently, I am using a table called "comment" with a foreign key referencing the "content" table, where each row contains 200 columns and each column signifies a single comment by a user. There is a cell for each.

Is it a good way for making a comment section for my website? Is there any other way which is better than this?

share|improve this question
No. it is not a good design. lookup 3rd normal form –  Mitch Wheat Jan 30 '11 at 4:59
@Mohit - Is the table named "Content"? Can you try to clarify this a little bit please? Thanks! –  jmort253 Jan 30 '11 at 5:00
So you do see the problem here, don't you? What happens to the 201st comment? I suggest you read up on database normalization. –  Ranhiru Cooray Jan 30 '11 at 5:00
@jmort253yes the name of table is content !!!! where there are 5 coloumns title, content, id, author, datetime. –  Mohit Jan 30 '11 at 5:02
@Ranhiru Cooray - i agree with u !! Thats way i am asking for a better solution of such problem !! –  Mohit Jan 30 '11 at 5:03
show 1 more comment

1 Answer

Basically, what you need to do is create a table called "Comments" that has a primary key for each comment. The table would have a foreign key linking back to your "content" table.

If you have 5 comments in the "comments" table, and 3 are for one post and 2 are for another, then there would be 3 rows, each containing a comment. There would be 5 separate primary keys, and 3 rows with the same foreign keys and 2 rows with the same foreign keys.

This would give you a one to many relationship between your content and comments. An inner join SQL query could get all of the comments for a single content entry.

Ranhiru is right, you should do some research on relating inner joins and foreign keys. This example shows several people enrolled in two courses, where a person can be enrolled in more than one course.

share|improve this answer
- if i have more than 10,000 rows in Content table and there are about 20 or more comment for each row i.e. total 2,00,000 or more comments in comment table !!! it will be fast enough to load the page within a secoend ????? –  Mohit Jan 30 '11 at 14:41
@Mohit - That depends a lot on the database you are using and how well you write your query. Two different queries that return the same data can have very different results. But having 200 columns in your table for comments is definitely not a normalized table, and it's definitely not a best practice. Normalization exists for a reason, and to fully understand why, you are going to have to do some research as @Ranhiru suggested :) –  jmort253 Jan 30 '11 at 21:39
add comment

Your Answer


