Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database structure of Facebook to store comments and post? [closed]

I'm going to create simple social networking site. so... I want to know that how Facebook store comments for posts.

is Facebook store Posts and its comments in same database table row, then how they store a long list of comments in a one table row field. or is it have each database table for each post, so that can make the comments for that post in that table row.

What is the best database structure for a simple social network site like CMS. but it could be handle a large amount of users.

Please help me in this matter. Thanks.

like image 238
Milan Avatar asked Oct 16 '13 10:10

Milan


1 Answers

Small example of what you could do:

Table users:

users
--------
id
name

Table comments:

comments
--------
id
comment_text
posted_by
posted_to
date_posted

When user with ID 342 posts a comment to user 783's profile, you can store the comment like so:

INSERT INTO comments(comment_text, posted_by, posted_to, date_posted) 
VALUES ('Hi!', 342, 783, '2013-10-16 11:17:00');

Then, when you're selecting comments to show on a user's profile, simply join the posted_by and posted_to columns up with the relevant ids in the users table.

like image 176
Wayne Whitty Avatar answered Sep 27 '22 21:09

Wayne Whitty