数据库设计—何时拆分表?

时间:2022-01-17 12:49:02

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

有时候,创建一个单独的表会产生更多的工作,我应该把它拆分吗?

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.

例如:我在项目表的客户,每个客户都有自己的特殊价格为每个产品(只有5产品&不计划在未来更多的产品),每个客户也有独特的一周内的公司提*品。

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?

很多操作,比如为客户更改天数/价格,或者显示所有客户的天数和价格,当天数和产品价格是客户表中的列,而不是单独的表时,就会容易得多,所以在这种情况下,只创建一个大客户表是否被驳斥?缺点是什么?

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?

更新:他们刚刚告诉我,大约一年后,他们有可能增加更多的产品,他们说他们的业务不会超过20-30个产品。我还是不明白为什么在这种情况下,当产品的价格没有关系(每个客户都有自己的特殊价格)时,往产品表中添加行比往客户表中添加列更好?我能想到的唯一好处是,只有5个产品的客户不需要“携带”20个无效产品(节省服务器空间)?我没有太多的经验所以也许我错过了显而易见的东西?

2 个解决方案

#1


3  

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

显然,仅仅说一个人应该永远正常化是不现实的。没有建议总是正确的。

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.

如果你能肯定地说5个“项目”足够你用很长时间,我认为如果它能节省你的工作,把它们作为列来保存是很好的。

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.

如果预测失败,需要存储第6项,可以添加一个新列。只要列的数量不太可能失控,这应该不是问题。

Just be careful with such tactics as the ability of many programmers to predict the future turns out to be very limited.

只要小心这种策略,许多程序员预测未来的能力是非常有限的。

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

最后,只有一件事是重要的:以最低的成本交付所请求的解决方案。代码的纯度不是目标。

#2


2  

Normalization is all about data integrity (consistency), nothing else; not about hard, easy, fast, slow, efficient and other murky attributes. The current design almost certainly allows for data anomalies. If not right now, the moment you try to track price changes, invoices, orders, etc, it is a dead end.

标准化是关于数据完整性(一致性)的,没有别的;不是硬的,容易的,快的,慢的,有效的和其他模糊的属性。当前的设计几乎肯定会考虑到数据异常。如果不是现在,当你试图跟踪价格变化、发票、订单等的时候,这是一个死胡同。

#1


3  

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

显然,仅仅说一个人应该永远正常化是不现实的。没有建议总是正确的。

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.

如果你能肯定地说5个“项目”足够你用很长时间,我认为如果它能节省你的工作,把它们作为列来保存是很好的。

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.

如果预测失败,需要存储第6项,可以添加一个新列。只要列的数量不太可能失控,这应该不是问题。

Just be careful with such tactics as the ability of many programmers to predict the future turns out to be very limited.

只要小心这种策略,许多程序员预测未来的能力是非常有限的。

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

最后,只有一件事是重要的:以最低的成本交付所请求的解决方案。代码的纯度不是目标。

#2


2  

Normalization is all about data integrity (consistency), nothing else; not about hard, easy, fast, slow, efficient and other murky attributes. The current design almost certainly allows for data anomalies. If not right now, the moment you try to track price changes, invoices, orders, etc, it is a dead end.

标准化是关于数据完整性(一致性)的,没有别的;不是硬的,容易的,快的,慢的,有效的和其他模糊的属性。当前的设计几乎肯定会考虑到数据异常。如果不是现在,当你试图跟踪价格变化、发票、订单等的时候,这是一个死胡同。