Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

database design - when to split tables?

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.

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?

like image 552
BornToCode Avatar asked Jul 16 '12 19:07

BornToCode


2 Answers

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.

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.

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.

like image 107
usr Avatar answered Oct 04 '22 02:10

usr


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.

like image 34
Damir Sudarevic Avatar answered Oct 04 '22 02:10

Damir Sudarevic