views:

38

answers:

2

There are products, sections and attributes.

Each attribute can have up to 5 or 6 options.

Example: Power

10 Volt
15 Volt
20 Volt

And there are about 10 products in total, each product has up to 17 attributes applied to it.

Example: Product 1

power - 10 volt
color - red, yellow
link - online, offline

How would you setup the tables? Im stumped. I was thinking of having a separate table for each attrubute, then a products table and sections table.

The products table would house foreign keys for the attributes that relate to it and sections. Does this make sense?

A: 

I was thinking of having a separate table for each attrubute,

Don't create a separate table for each attribute, this won't server your purpose.

Create separate tables for each of the products, sections and attributes and join them accordingly using PKs and FKs.

Sarfraz
Hmm that was my first thought. But I worry that the attributes table it going to get out on control
jrutter
@jrutter: no, it shouln't, you need to identify each attribute with corresponding FK of product in the same table and more than one record(attribute) could be inserted for a product. Thanks....
Sarfraz
A: 

This is quite common. You can have a base product table with some general attributes like...

Product
-------
ProductID
ProductName 
Description
Price

Then you can extend the table for different product types. So you could have a table like

ProductElectrical 
-----------------
ProductID
Voltage
Watts
BatterySize

Or...

ProductApparel
---------------
ProductID
Color
Size
Material

Then when needed you can join the extension tables to the core product table like this...

select p.ProductID, p.ProductName, p.Description, pa.Color, pa.Size, pa.Material
from Product p
join ProductApparel pa
on pa.ProductID = p.ProductID
where pa.Size = "XXL"

This way you can have a compact core product table used throughout your system. When you need to see the extra attributes you can easily join them to the core Product table.

Alex