一个或两个论坛论坛? [英] One or two tables for forum?

查看:137
本文介绍了一个或两个论坛论坛?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在建立一个论坛,我想知道我应该有一个表,我存储所有主要的帖子,然后所有的答案在另一个表。

Im building a forum and I'm wondering whether I should have one table where I store all main posts and then all the answers in another table.

ve总是将所有内容存储在一个表中,使它向东计数,并让用户评论每个帖子(另一个表中的注释)。

I've always stored everything in one table, making it east to count and let users comment every post (comments in another table).

我该怎么办?利弊?尝试到google但没有找到任何东西。

What should I do? Pros and cons? Tried to google but didn't find anything.

感谢您的帮助!

推荐答案

我通常遵循规则每种类型的数据集获得一个自己的表。这种方式你可以清晰地定义关系

I usually follow the rule every type of dataset gets a own table. This way you can cleanly define relationships

你有类似


  • userTypes

  • 帖子(有一个user_id)
  • $ b $ b
  • 回答(有一个post_id)

  • 评论(有一个post_id,有一个answer_id)

  • userTypes (e.g. guest,user,mod,admin)
  • users (has one userType_id)
  • posts (has one user_id)
  • answers (has one post_id)
  • comments (has one post_id, has one answer_id)

由于可以为帖子和答案添加注释,因此您可以添加两个桥接表来定义此关系。

Since comments can be added for both, a post and an answer, you could add two bridge tables to define this relationship.


  • comment_to_answer(有一个comment_id,有一个answer_id)

  • comment_to_question(有一个comment_id,有一个question_id)

如果你把两个,post和答案保存在一个表,posts表将需要引用自己定义的帖子 - 答案一对多的关系,这将使查询更复杂。

In case you save both, posts and answers into one table, posts table would need to reference themselves to define the posts - answers one-to-many relationship, which would make querying more complicated.

如果你想能够级联,post可以有答案,answer可以有答案等等,你可以更好地与一个posts表和parent_id指向id帖子

If you want to be able to cascade, post can have an answer, answer can have an answer and so on, you probably go better with one posts table and a parent_id pointing at the id of posts

希望这有助于。

这篇关于一个或两个论坛论坛?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆