对于用户“关注”/“朋友”的网站来说,什么是好的数据库结构?其他用户?
我正在为一个 Web 应用程序构建一个数据库,其中包含相互关注的用户。什么才是好的设计?我当时在想:
TABLE: users ROWS: user_id, name, pass, email, activated, user_level, registration_date
TABLE: relationships ROWS: relation_id, user_id, followed_id
你对此有何看法?
I am building a database for a web application that includes users following each other. What would be a good design? I was thinking this:
TABLE: users ROWS: user_id, name, pass, email, activated, user_level, registration_date
TABLE: relationships ROWS: relation_id, user_id, followed_id
What do you think of that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于用户表,我想你所拥有的是正确的。如果您需要添加更多列,您可以简单地更改该表,或者添加具有一对一关系的附加表。
至于关系表,我认为这是正确的。尽管我不会将其称为
followed_id
。我建议您可以将该表用于许多不同类型的交互,因此我将其称为user_id
和interacter_id
,而relationship_id
将是许多不同类型的交互(关注、戳等)。For the user table, I guess what you have is correct. If you need to add more columns, you could simply alter that table, or add an additional table with a one to one relationship.
As for the relationships table, I think that is correct. Although i wouldn't call it
followed_id
. I would suggest that you could use that table for many different types of interactions, so I would call ituser_id
andinteracter_id
and therelationship_id
would be a number of different types of interactions (follow, poke, etc).