I am trying to find the best way to store product size, colour for an sports store website, something similar to what amazon does, where you can choose a shoe colour and number. The problem is that a product may be a shoe shirt ball bag etc, so the sizing charts/systems to be used will all be different for different types of products. Also one product may have different sizes and different colours and some colours may not have a certain sizes or vice-versa? I am a rookie in database designing so I don't know how to approach this problem.
Mysql – the best way to store product size and color for an Ecommerce database
database-designMySQLsqlite
Best Answer
You will need to implement exclusive subtypes to handle the attributes for each product type. A (very) abbreviated example:
In this case
ProductTypeCd
works as a discriminator to define the subtype ofProduct
, which we would then define like so:There is some care that must be taken to ensure the tables align with the proper
ProductType
. Depending on the DB engine this would have to be handled via a trigger instead of a check constraint. This SO answer handles it in depth: https://stackoverflow.com/a/4898314/13942986From comments:
SQLite is not a relational database, MySQL barely so. Between the two, use MySQL.