How to store likes and comments of posts in database? I am building a social networking website, so I wanted to know how the database structure for storing likes and comments of a post.
I have created a table post for storing posts but I want to know how to store &quot;likes&quot; and &quot;comments&quot; so that I can show who are the people who liked your post and what are the comments of the post.
Do I need to create a table for likes which stores user id of every user who liked the post and post_id as foreign key, but this may be very large table as it will create a new row for every user who liked the post. For example if one post has 1000 likes then it will create 1000 rows for the same post in &quot;like&quot; table. The same thing happens with comments as well.
Please suggest me the table structure for post, like and comments. Thanks!
Doing it the way you suggested is the right way to keep track of likes. A separate table with user_id and post_id both of which are FK and these 2 FK combined can serve as PK

2 columns both of which are integers(or bigint) is not a problem to any RDMBS. 

In fact, 2 integer columns should be the least of your concerns. Because integers are one of the most performant datatypes, and occupy very little space if compared to, for example, nvarchar.

I think this SO post might help you as well https://stackoverflow.com/questions/11808680/database-design-table-of-likes