Question

alt text http://produits-lemieux.com/database.jpg

This is basicly my database structure

one product (let say soap) will have many retail selling size

  • 1 liter
  • 4 liters
  • 20 liters

In my "produit" database I will have the soap item (id #1) In the size database i will have many size availible :

  • 1liter
  • 4liter
  • 20liter

How not to duplicate the product 3 time with a different size... i like to be able to have check box in the product size of all the size available in the database and check if yes or no (boolean)


The answer a got is perfect, but how to have the option like that :

soap [x] 1 liter , [ ] 4 liter , [x] 20 liter

Was it helpful?

Solution

I'm not sure I understand your exact scenario, but to create a many-to-many relationship, you simply create a "relationship table", in which you store id's for the two records you want to link.

Example:

Products
********
ProductID (PK)
Price

Retailers
*********
RetailerID (PK)
Name

ProductRetailerRelationships
****************************
ProductID
RetailerID

OTHER TIPS

A many-to-many relationship is almost always modeled using an intermediate table. For your example,

Product
--------
prod_numero
...

Size
--------
size_numero
...

Product_Size
--------
prod_numero
size_numero
...

The Size table would contain particular sizes (say, 10 liter) and the Product_Size table creates a Product and Size pairing.

You Will need an Intermediary, or "Join" Table

ProductSizes
.......................
ProductID
SizeID

One record for each product-size combination

Based on the answers, here is the database tables layout as proposed, it look complicated to me, but are you sure it is the way to do this, the BEST solution ?

alt text http://produits-lemieux.com/database2.jpg

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top