简体   繁体   English

MYSQL数据库结构与设计

[英]MYSQL database structure and design

I'd like to program my own forum for learning purposes and I need some help in planing database structure. 我想为自己的论坛编程以便学习,并且在规划数据库结构时需要一些帮助。

I want to achieve following task: 我要完成以下任务:

  1. I want to store members in database 我想将成员存储在数据库中
  2. Each user can create new threads 每个用户都可以创建新线程
  3. Each thread can be commented by every member 每个成员都可以评论每个主题

My own approach would be... 我自己的方法是

  1. Table for members 会员表
  2. Table for threads 螺纹表
  3. When user creates new thread, system dinamicly creates new table COMMENTS_THREAD_ID and all comments associated with this thread would be included in this table 当用户创建新线程时,系统将动态创建新表COMMENTS_THREAD_ID,与此线程相关的所有注释都将包含在该表中

Is it good practice to create separate table for comments for each thread? 为每个线程的注释创建单独的表是一种好习惯吗? What if site would get popular and there would be thousands of threads daily? 如果该站点将变得流行并且每天有数千个线程怎么办? Could you suggest structure that would suite this type of scenario? 您能否建议适合这种情况的结构?

Thanks 谢谢

How about a single SQL table Comment , with fields id , thread_id , member_id and body those fields will be enough to organize your data 带有字段idthread_idmember_idbody的单个SQL表Comment怎么样,这些字段足以组织您的数据

I think creating a new SQL table every time a Thread is created is an expensive operation (even if MySQL doesn't impose a hard limit on the number of tables within a database), overall I think RDBMS are more row-centric than anything else (add a new comment row instead of creating a new table) 我认为每次创建Thread时创建一个新的SQL表都是一项昂贵的操作(即使MySQL并未对数据库中的表数施加硬限制),总的来说,我认为RDBMS比其他任何东西都更以行为中心(添加一个新的注释行,而不是创建一个新表)

No, that is not good practice. 不,那不是一个好习惯。 You don't need a table for each thread's replies. 您无需为每个线程的回复提供表格。 You can just use a replies table for all of them, if you add a column to it that denotes to which thread each reply belongs. 你可以只用一个replies表, 所有的人,如果你添加一列它,表示每个回复属于哪个线程。

That's how RDBMS work. 这就是RDBMS的工作方式。 Lists of things, put in relation to each other through foreign keys. 通过外键相互关联的事物列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM