Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2006

    Unanswered: associate each product with multiple bikes (was "How should i.....")

    Hello, im brand new to these forums, scrolled through a bit of the forum(mainly trying to figure out how to go about what im about to ask) and it seems like a good forum...anyways onto my question.

    i am in need of ideas/know-how on how to structure a database like such:

    its an online motorcycle accessories website, and this is the information i need to store in the db(basically these will be my tables in the db)

    bike manufacturer
    bike name

    now my main question is how would i structure those tables so i can get this effect.

    each product in the product table needs to have a bike associated to it, 99% of the time it will be more than one bike associated to it, so how would i go about doing that?

    originally i had set it up with the bikes name being different columns in the products table with a bit type set to 1 if that product was available for that bike and 0 if it wasnt available. however as you are probably already thinking that isnt the best way to do that.

    so what is the best way?

    any info at all would be greatly appreciated.

    thanks in advance

  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    if the products table has product_id as its PK, and if the bikes table has bike_id as its PK, then you need

    create table bikeproducts
    ( product_id integer not null references products(product_id)
    , bike_id integer not null references bikes(bike_id)
    , primary key(product_id,bike_id)

    this "relationship" or "linking" or "many-to-many" table allows you to add a row for each occurrence of a relationship -- one bike, multiple products, and one product, multiple bikes | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Aug 2006
    Thank you very much, that makes alotta sense, and i understand what i have to do, thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts