database design - Table structure for web shop -


please consider scenario:

a web shop sells products. if @ computers , printers, there filters both products need: id, name, price, e.d. filters specific 1 product: os, cartridge type.

what best way store these products?

  1. i thinking this.

create product table possible filters. if product doesn't have filter, keep empty. method simple implement can cause lot of waisted space if there many different specific filters.

  1. this wordpress way of doing it.

create product table general filters. create separate table holds meta data (specific filters) these columns: filter_id, product_id, filter_name, filter_value. every specific filter gets it's own row. method doesn't waste space, if every product has around 10 different specific filters, table become large , might cause more performance issues first method.

could tell me method preferred way, or maybe give alternative.

thanks

what you're looking m:n relationship (i.e. filter might apply multiple products, , product might have multiple filters) described here: best way design table m:n relation

you have twist of being interested in possible values. recommend 4 tables:

  • table 1 has products (productid, productname, price etc.) list possible products
  • table 2 has filters (filterid, filtername etc.) list possible filters (but not possible values)
  • table 3 has relation (productid, filterid) indicating that filter appropriate product. fk both products , filters
  • table 4 has filter values: (filterid, filtervalue) fk filter listing each possible value given filter.

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -