views:

126

answers:

2

I have a 'customers' table. Each record contains a customer name, email, address, etc.

I have an 'skus' table. Each record contains the name of an SKU. e.g. "Super Software Bundle".

An SKU represents a purchaseable item at a single price point. The purchased item can include one or more products.

e.g. The SKU record named "Super Software Bundle" may represent two products: product1 and product2.

For usability/ease reasons, other tables need to keep track of not only skus purchased, but the individual products a customer may have access to.

Question: how should I represent the variable sized nature of the SKUs in the database, where an SKU can represent from 1 to n products? Thanks for any help.

A: 

If I'm reading this right, you'll need a SKU table and a products table, and the products table will have a foriegn key to the SKU table.

Evernoob
Thanks for the response. That's the part I'm having difficulty with. How would I set up the SKU tables and products table, such that the SKU table can reference a variable number of records in the products table?
SirRatty
Been thinking more on this. Are you saying that in order to get the list of products per SKU, I should search in the products table, for all records with FKs relating to the specific SKU id?
SirRatty
A: 

You will need a third table, that manages the relation between SKU and products, as a product may be part of more than one SKU (I guess). You have to model a m:n-relation.

product

  • id
  • name
  • price
  • ...

sku

  • id
  • name
  • price
  • ...

*sku_product*

  • id
  • sku_id
  • product_id
zaphodbln
Thank you for your help with this. I shall try this approach.
SirRatty