I’m having a hard time taking this decision. I have a schema where I want a product from a specific category to have specific values from that category.
I’ve made my way in to 5 tables and I just want to know if this is the right way of doing it.
Scenario:
Main tables:
Element (id, name, category_ID)
Category (id, name)
Characteristic (id, name, unity)
I want a Category to have specific number of Characteristics (ie. a computer needs to have the characteristics of cpu, ram, screensize, etc. and a mouse needs to have isCordless, numberOfButtons, etc.), so I’ve created the table Category_has_Characteristic:
Category_has_Characteristic(id_category, id_characteristic)
For setting the specific element value to each characteristic from the category I’ve created this table:
Element_has_Characteristic ( id_element, id_Category_has_Characteristic, value)
is this the best approach to create a table to have the specific element values for each characteristic ?
Am I missing something or this is the only/best way of doing it?
any comment will be highly appreciated.
This sounds like a classic case of overnormalization. Consider a table:
This leads to way simpler queries. You only need a many-to-many relation if your characteristics are dynamic. For example, if you’re planning to write a control panel that your users can use to add characteristics to a category.