简体   繁体   English

MySQL数据库结构优化

[英]MySQL database structure optimization

In my DB project for website which will be created using PHP I have round 60 tables with 2 to 6 columns in each. 在我的网站数据库项目(将使用PHP创建)中,我有60个表格,每个表格2至6列。 Some of them can have thousands records, some hundreds and some only a few (1-10). 其中一些可以具有数千条记录,一些可以有数百条记录,而只有几条记录(1-10)。 These tables where are only a few records are the one that describe user type or city size from where later in other table is only reference to this. 这些表中只有几条记录是描述用户类型或城市规模的记录,而其他表中稍后仅引用此记录。 The bigger tables are for example the user contact data info. 较大的表是例如用户联系数据信息。

What I guess is also important in this architecture is that the tables are created the way that only inserts are complex because for example user insert (creation) is operation that is inserting values to 6 tables. 我猜想在此体系结构中还很重要的一点是,表的创建方式只有插入是复杂的,因为例如用户插入(创建)是将值插入6个表的操作。 But all updates or queries are done generally on max 3 tables. 但是所有更新或查询通常在最多3个表上完成。

With such big database I am wondering is it better to stay with smaller tables and during query make it more complex call, or create fewer tables with bigger number of columns? 对于这么大的数据库,我想知道保留较小的表,并在查询期间使其更复杂地调用还是创建较少的具有较大列数的表,会更好吗?

If staying with smaller tables is better then should I use JOIN, create some VIEW, or maybe something else? 如果最好使用较小的桌子,那我应该使用JOIN,创建一些VIEW或其他方法吗?

I hope I've explained completely my concerns and how database looks like. 我希望我已经完全解释了我的担忧以及数据库的外观。

Thank you for answers in advance. 预先感谢您的答复。

In my view you should stay with smaller tables. 我认为您应该留在较小的桌子上。 because it is easy to maintain data in them. 因为很容易在其中维护数据。 Also Normalise your database. 规范化数据库。 save reference in your master Tables. 将参考保存在主表中。 Use foreign keys to make relationships between tables. 使用外键在表之间建立关系。
Than use joins to fetch data you want its very easy. 比使用联接来获取数据要简单得多。 I always follow this approach. 我一直遵循这种方法。 and one thing Only You Know What is best suitable for you . 一件事只有你知道什么最适合你。

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

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