How to create a comment table in SQL

Suppose there is a table called "content" where each row means unique content for my site.

Now I want to add a comment section to each unique content, or you can say every row of the table. I am currently using a table called β€œcomment” with a foreign key referencing the β€œcontent” table, where each row contains 200 columns and each column represents one user comment. For each there is a cell.

Is this a good way to make a comment for my site? Is there any other way that is better than this?

+3
source share
1 answer

Basically, you need to create a table called "Comments" that has a primary key for each comment. The table will have a foreign key linked back to your table of contents.

If you have 5 comments in the comment table, and 3 for one entry and 2 for another, then there will be 3 lines, each of which contains 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 will give you a correlation between your content and comments. An internal SQL connection request can receive all comments for a single content entry.

Ranhiru , . , , .

+2

Source: https://habr.com/ru/post/1788759/


All Articles