Search code examples
databasemany-to-manyrelational

Database relation many to many


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


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