Good day everyone. I am building a database for an application and I have thought of two different approaches for achieving the same result, and I would like your opinion.
Is basically the classical product database, so at the moment I have products, each of theme belonging to a category. Each product has different features but the products that fall in the same category all share some common features.
At the moment I thought of this two structures:
- A products table, just to store the name.
- A product_categories table, to store the categories, and an intermediate table to link both.
- A features table, to store the different features.
- A product_features to link the product with it's features and store their value.
Since the products that fall on the same category have some shared features, I also thought of extracting the common features and creating a table for each product, so the result would be something like this:
- A table for each product, to store their name and common features.
- A features table, to store the different features that are not common.
- A product_features to link the product with it's features and store their value.
I believe the first structure will be easier to maintain if I need to add newer products down the line as I would not need to create any new tables, but I kind of feel that the second approach would be more correct.
Let me know your thoughts!
Best Answer
If a category has related features then you have to link them independently from product. If a
feature
is only present through acategory
then you can omit the link betweenfeature
andproduct
. If not, you have to linkfeature
with bothcategory
andproduct
, or else you might have inconsistencies between a product category's features and the actual features for that product.Assuming that a category has a set of features and a product might have specific features (aside from those from it's category), I would suggest the following scheme:
So if you want to retrieve a specific product's features you have to traverse through it's categories and particular features:
Following this approach, you just have to add a category to a product to "inherit" it's features, and you have the possibility to add custom features to particular products. Also changing the features of a category will automatically impact all products related to that category.