开发者

MySQL - Multiple tables vs. single table

I have been working on saving/loading, and I came across that I have to load/save a lot of tables, because I split my tables into categories e.g. characters, character_appearance, character_preferences, character_session, etc. (I use the LEFT JOIN clause to load)

Would it be better if I just put all the columns into a 开发者_运维技巧single table instead of splitting it into multiple tables?

I generally split them into multiple threads because I thought I would have too many columns inside the table which could cause issues.

Any opinions whether I should use a single table / multiple tables?


It all depends on your design. Does a character have more than one appearance? If so then character_appearance would belong in its own table. If however a character only has one appearance then it would belong in the character table. The number of columns that you have in a table is not an issue as long as each column actually depends directly on your primary key.

I would imagine that a character can have several preferences, in which case you will need to create a spearate preferences table. What about sessions? One per character or multiple? The question is what does a session actually depend on? The character id or something else?

Maybe a single character can have several sessions at different times. If that is the case then a session does not depend on the character's primary key but on the time as well as the character's primary key. In which case it does not belong in the character table but in a table by itself.


Multiple tables: It's generally cleaner to have a table per domain class, both from a modelling and maintenance perspective.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜