database 社交网站的数据库设计

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3271182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 07:47:33  来源:igfitidea点击:

Database design for a social networking site

databasedatabase-designsocial-networking

提问by Andy Robinson

What are the Tables that would be present in a social networking site (ex: Twitter).

社交网站(例如:Twitter)中会出现哪些表格。

I have a users table as of now. How to keep track of followers and people I do follow?

到目前为止,我有一个用户表。如何跟踪关注者和我关注的人?

  • Should I maintain a separate table for followers and people I follow?
  • What are the columns which would be there in those tables?
  • 我应该为关注者和我关注的人维护一个单独的表格吗?
  • 这些表中会有哪些列?

Please don't think this as Subjective/Off topic. As I am a beginner, I thought experts can guide me to get a good DB design?

请不要认为这是主观/偏离主题。由于我是初学者,我认为专家可以指导我获得一个好的数据库设计吗?

回答by Andy Robinson

Try having a look at Database Answersin particular the data models. They have several different designs for various systems. This oneis for a social networking site which may give you an idea of what's required.

尝试查看数据库答案,特别是数据模型。它们对各种系统有几种不同的设计。这一个是社交网站可以让你真实需要什么样的想法。

You may want to search on SO for other social network database questions. I found this onethat had a link to flickrshowing a schema which appears to be from Facebook.

您可能想在 SO 上搜索其他社交网络数据库问题。我发现这个有一个指向flickr的链接,显示了一个似乎来自 Facebook 的模式。

Your database design will be based around your system requirements. Without knowing exactly what you are trying to achieve, it is difficult to give you the best design.

您的数据库设计将基于您的系统要求。如果不确切知道您要实现的目标,就很难为您提供最佳设计。

回答by Sadegh-khan

you can use this Messenger Database Design Concept: Messenger DB

您可以使用此 Messenger 数据库设计概念:Messenger DB

Messenger DB Schema

信使数据库架构

回答by user3375663

You can create a separate table for follower/ followed relationships. So, when x follow y, create an entry with follower_id = x.id followed_id = y.id.

您可以为 follower/ follower 创建一个单独的表relationships。因此,当 x 跟随 y 时,创建一个带有 的条目follower_id = x.id followed_id = y.id

You can query the relationship table to look for all the users x has relations with by select * from relationships where follower_id = x.idor vice versa.

您可以查询关系表以查找所有与 x 有关系的用户,select * from relationships where follower_id = x.id反之亦然。

When/if x un-follow y, you just have to delete the entry you originally created.

当/如果 x 取消关注 y,您只需删除您最初创建的条目。