Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004

    Unanswered: Many to Many relationship

    Hi All,

    I have a two tables. One is Product and another is Supplier.
    I would like establish a Many To Many relation between this to.
    One product can supply by many suppplier and at the same time one supplier can supply many product.

    Could any one please help me how to establish the same?

    Prodduct Supplier
    -------- --------
    Product_ID Supplier_ID
    Prod_Name Sup_name

    Thanks with Regards,

  2. #2
    Join Date
    Jun 2004
    Liverpool, NY USA
    This looks to much like homework. So us your ideas and then we will help you. We dont do homework on this forum.
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  3. #3
    Join Date
    Apr 2002
    Toronto, Canada
    the many-to-many table looks like this --
    CREATE TABLE product_suppliers
    ( product_id INTEGER NOT NULL
    , supplier_id INTEGER NOT NULL 
    , FOREIGN KEY ( product_id ) REFERENCES products ( product_id )
    , FOREIGN KEY ( supplier_id ) REFERENCES suppliers ( supplier_id )
    , PRIMARY KEY ( product_id, supplier_id )
    @beilstwh: yes, it looks like homework, but it also looks like a dumbed-down example of two completely different tables | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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