Mysql:为每个用户的帖子创建一个单独的表是否可行 [英] Mysql: Is it practical to create a separate table for each user's posts
问题描述
所以我有一个网站,用户可以在其中创建自己的商店",然后他们可以将商品放入商店,那么为每个用户的商店创建一个表格是否可行,或者我应该只在帖子中添加用户 ID?
So i have a website where users create their own 'shops' and then they can put items in the shops, so would it be practical to create a table for each user's shops or should I just add user IDs to posts?
推荐答案
您应该将用户 ID 添加到商店/帖子.您不想为每个用户使用单独的表的原因有很多:
You should add user ids to shops/posts. There are numerous reasons why you do not want to have separate tables for each user:
- MySQL 旨在处理具有大量行的表,而不是具有相同结构的大量表.
- 构建跨表的查询需要组合大量不同的表.
- 数据结构的一个小改动,比如添加一个新列,就会变成一场噩梦.
- 对商店的外键引用变得不可能.
- 如果用户的数据没有填满单个数据页,您最终会浪费大量内存.
可能需要将数据拆分到单独的表中有一些原因.以下是一些可能的原因:
There are some reasons why splitting data into separate tables might be necessary. Here are some possible reasons:
- 在表级别比在行级别更容易管理访问.
- 复制每个用户的数据可能有不同的要求.
- 外部实体要求数据位于单独的表或数据库中.
然而,第一组原因似乎对单个表/实体结构的影响更大.这些更高级的问题似乎不是问题.
However, the first set of reasons seems to weigh much more heavily to single table/entity structures. These more advanced concerns do not appear to be an issue.
这篇关于Mysql:为每个用户的帖子创建一个单独的表是否可行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!