本文介绍了数据库设计-何时拆分表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候创建一个单独的表会产生更多的工作,我是否应该将其拆分?

Sometimes creating a separate table would produce much more work, should I split it anyway?

例如:在我的项目中,我有在一张客户表中,每个客户对每种产品都有自己的特价(只有5种产品,并且将来没有计划中的更多产品),每个客户在每个星期都有自己独特的时间公司向他交付产品。

for example: In my project I have a table of customers, each customer has his own special price for each product (there are only 5 products & more products are not planned in the future), each customer also have unique days of the week when the company delivers to him the products.

许多操作,例如更改客户的天数/价格,或显示天数&当日子和日子过后,所有客户的价格将容易得多。产品价格是客户表中的列而不是单独的表,因此在这种情况下是否仅创建一个大客户表被驳斥?缺点是什么?

Many operations like changing days/price for a customer, or displaying days & prices of all customers would be much easier when the days & product prices are columns in the customers table and not separate tables, so is it refuted to create only one big customers table in such case? What are the drawbacks?

更新:他们只是告诉我,大约一年后,他们有可能添加更多产品,他们说他们的业务在任何情况下都不会超过20-30个产品。
我仍​​然不明白为什么在这种情况下,如果产品的价格没有关系(每个客户都有自己的特殊价格),那么将行添加到Products表中要比向Columns客户表中添加行更好?
我唯一想到的好处是,只有5种产品的客户不必携带 20种可空产品(节省服务器空间)?我没有太多经验,所以也许我错过了显而易见的事情?

UPDATE: They just informed me that after a year or so there's a chance that they add more products, they say their business won't exceed 20-30 products in any event.I still can't understand why in such case when product's prices has no relation (each customer has his own special price) adding rows to Products table is better then adding Columns to Customers table?The only benefit I could think of is that customer that has only 5 products won't have to 'carry' 20 nullable products (saves space on server)? I don't have much experience so maybe I'm missing the obvious?

推荐答案

很显然,只是说一个人应该总是规范化并不务实。没有建议总是正确的。

Clearly, just saying that one should always normalize is not pragmatic. No advice is always true.

如果您可以肯定地说5个项目足够长时间了,我认为将它们存储为

If you can say with certainty that 5 "items" will be enough for a long time I think it is perfectly fine to just store them as columns if it saves you work.

如果预测失败并且需要存储第六项,则可以添加一个新列。只要列数不会非常高地失控,这就不成问题。

If your prediction fails and a 6th items needs to be stored you can add a new column. As long as the number of columns doesn't get out of hand with very high probability, this should not be a problem.

请谨慎使用许多程序员预测未来的能力非常有限。

最后,只有一件事很重要:在Web站点交付所需的解决方案。最低的成本。代码的纯度不是目标。

In the end only one thing counts: Delivering the requested solution at the lowest cost. Purity of code is not a goal.

这篇关于数据库设计-何时拆分表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 02:33