简体   繁体   English

MySql 多表还是一张大表?

[英]MySql multiple tables or one big table?

I am currently making an agency CMS and would like to ask about user details.我目前正在制作一个代理 CMS,想询问用户详细信息。 So the registration form is split to 2 groups, Photographers and Models.所以报名表分为两组,摄影师和模特。 Models can select options about their body type, suc as Hair color, Hair Lenght, Height and other, but these options are not needed for photographers.模特可以选择关于他们的体型的选项,如头发颜色、头发长度、身高等,但摄影师不需要这些选项。

My question is, wich is more effective?我的问题是,哪个更有效? Storing everything in a big table or spliting the body detalis.将所有东西存放在一张大桌子中或拆分身体细节。

Example例子

users_table <--- contains everything

or要么

users_table <--- containing login details and a few basic information
users_body_table <--- containing model body information

If someone could give me some info about this would be happy如果有人能给我一些关于这方面的信息会很高兴

thank you folks谢谢你们

From your description I would definitely recommend going with second approach - splitting the data.根据您的描述,我绝对建议您使用第二种方法 - 拆分数据。

You should notice that in the first approach you will have roughly one quarter of the table filled with nulls.您应该注意到,在第一种方法中,您将有大约四分之一的表填充空值。

About nulls effect you can see for example here关于空值效果,您可以在这里看到例如

The most important thing that will determine which is more efficient is how much you will need only get Photographers or only Models.决定哪个更有效的最重要的事情是您只需要获得摄影师或仅需要多少模型。 For me it's quite clear that probably often - and because of that, with split table it will be better.对我来说很明显,可能经常 - 正因为如此,使用拆分表会更好。

And maybe if you will meet some need of changes, it will be easier to maintain to change it for only one table (if for example some new Model trait will be added).也许如果您将满足某些更改需求,那么仅针对一个表更改它会更容易维护(例如,如果将添加一些新的模型特征)。

Think in terms of future normalization从未来正常化的角度考虑

With a splitted tables you can easily run through one table if you want just retrieve data on this.如果您只想检索有关此表的数据,则使用拆分表您可以轻松浏览一张表。 If your big table have a lot of data the time of retrieving will be too much.如果你的大表有很多数据,检索的时间会太多。 if you map the table to object it is better to have a small object.如果将表映射到对象,最好有一个小对象。 you can reuse it too.... Maybe you can use view if you want really one table (view is a transparent dynamic table)你也可以重用它......如果你真的想要一张表,也许你可以使用视图(视图是一个透明的动态表)

Good way is separate tables.好方法是单独的表。 One table for common details (users) (login, password, etc) Second table for models (users_models) and 3rd table for photographers (users_photo)一张表用于常见详细信息(用户)(登录名、密码等) 第二张表(users_models)和第三张表(users_photo)

In table users you can make 2 fields for store id from models and photo tables.在表用户中,您可以为模型和照片表中的商店 ID 创建 2 个字段。 In this case one user can be model or/and photographer.在这种情况下,一个用户可以是模特或/和摄影师。

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

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