Inventory management with stock options

I think the draft model (following 6NF and 3NF) will help you.
I simplified naming convention by removing ‘shop’ keyword.
(Also shop entity may leads a separate concept AKA SaaS)

SqlFiddle Demo

enter image description here

About the questions in the comments:

Is it possible to have a unique product ID

Yes, it is a common pattern to use surrogate identifier on your tables. As you may see in the article, that will come with its pros and cons.

For example, in the question, you will see that primary key of ProductSpecification table is a composition of ProductTypeOptions, OptionValue and Product foreign keys.
In the mean time primary key of other tables like OptionValue is a composite key (OptionId + ValueName)
It looks like life will be more easy to have an ID field in every table as the primary key, yes it is but as a database designer you will loos something valuable, business logic.

In the current design you can have these constraint in Product-Specification table, they will show part of your business logic:

  • Check constraint on ProductSpecification {OptionValue.optionId =
    productTypeOption.optionId}
    that will prevent a value like “White”
    being assigned to “Size”.
  • Check constraint on ProductSpecification {product.productTypeId =
    productTypeOption.productTypeId}
    that will prevent a product like
    “Nike” being assigned to productSpecifications of “Cars”.

If you use surrogate identifier you can not have these type of constraints inside your data base (try this).
Extra work will be needed to be done inside you application implementation to gain them.
BTW use surrogate identifier, check data consistency, if more interested see choosing a Primary Key: Natural or Surrogate.

Where should the base price, stock, and surcharge go?

It seems that “Mens Shoe” of “Nike” needs to have price, stock and surcharge, so they are natural property of Product table.

Leave a Comment