[英]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: 我要完成以下任务:
My own approach would be... 我自己的方法是
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 带有字段id
, thread_id
, member_id
和body
的单个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.