• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 426
  • Last Modified:

DB Design for Product and Subproduct Tables

We have a database which holds a list of products in a Product table. Each product can contain one or more subproducts, each of which is characterised by a product type. This is how I was thinking of designing the relevant tables:

- Subproduct Type Table (PK Subproduct Type ID, Subproduct Type description);
- Product Table (PK Product ID, Product attributes) has a one to many relationship with
- Subproduct Table (PK Subproduct ID, FK Product ID, FK Subproduct Type ID, Subproduct attributes).

However, someone has suggested to me the following design, which apparently should help queries to run faster:

- Product Table (PK Product ID, Product attributes) has a one to many relationship with
- Subproduct Type Table (PK Subproduct Type ID, FK Product ID, Subproduct Type description) has a one to many relationship with
- Subproduct Table (PK Subproduct ID, FK Subproduct Type ID, Subproduct attributes).

Which design would you recommend? I have worked with databases before, but I have never designed one from scratch.
0
Rothbard
Asked:
Rothbard
  • 4
  • 3
1 Solution
 
imitchieCommented:
It really depends on what sort of typical queries you expect to run in the future, as well as whether the relationship makes sense at all!
0
 
imitchieCommented:
Your original design allows for

Product: Car, Truck, Van, Bike  (vehicle)
SubProduct: LightVan, Tricycle, ForkliftTruck
SubProductType: Budget, MidRange, Premium.

So you can Budget-car, budget-van, premium-bike etc, with SubProduct in the middle.

However the suggested design swaps this all around.

Product: Car, Truck, Van, Bike  (vehicle)
SubProductType: PremiumCar, BudgetCar, LightBike, CompactCar, PremiumVan
SubProduct: etc etc

You see how the relationships are completely different. It makes a lot less sense to change your design, unless you have 10million records and 2000 product types and a slow database engine.  Then maybe the 2nd design can serve the query "Budget cars" a little faster, but not even by much.
0
 
RothbardAuthor Commented:
Sorry, I should have clarified what I meant. The relationship between Product and Subproduct is a "has a" one. A better description would have been "Product" and "Component". Each Product is made up by 1 to 5 Components. We have tens of thousands of Products and Components. In total there are only about 10 different Component Types.

If we choose the first design, we are going to have a very small Component Type table, with 10 different entries listing all the Component Types in the system. The Component table is linked to the Product table by a Product ID foreign key, and to the Component Type table by a Component Type ID foreign key.

If we choose the second design, the Component Type table will have a separate entry for each Product, i.e. it will have Product ID as a foreign key. The Component table then has only got a Component Type ID foreign key.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
imitchieCommented:
I did understand that.  I was just illustrating that they have very different meanings.  Your "small items" category has to be replicated for each Product in the 2nd scenario.
0
 
RothbardAuthor Commented:
So you would recommend the first scenario?
0
 
imitchieCommented:
For me personally, yes, it makes a lot more sense relationally.
But as with all things, only you would know best. What works 90% of the time may just not work if you fall into the 10% category.
If you had good indexes on the foreign keys on Component, I can't see why it should be much slower, if any.
0
 
RothbardAuthor Commented:
Sorry for the delay, I had forgotten to accept your answer. Thanks.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now