Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003
    Posts
    6

    Unanswered: Insert Records in a two tables with many-to-many relationship.

    Hi, i have a dude and i expect that someone here can resolve it:

    I have one table of products and a table of suppliers and they are relationed with a many-to-many relationship. Therefore i have a third table (junction table) that contains the pks of each one and the quantitie of product. My dude consists when i insert a new record for a new product, how manage the junction table?? Manually with code i'll insert a new record with both keys (new product and supplier that provides it to me) too and the quantitie or the dbms do that automatically??

    Thanks...
    Last edited by carlos_ponce81; 01-10-05 at 14:41.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I would do it as a separate statement. When you add a new product, there isn't any way I understand to predict which supplier(s) might be able to supply it, much less which supplier(s) actually supply that product. That is a decision that I'd leave to human intervention.

    -PatP

  3. #3
    Join Date
    Aug 2003
    Posts
    6

    Thanks!!

    Ok, thanks, that was my dude. So, in two statements i insert the two records, one in the products table with product's info (product key, product name, etc) and one in the product details with the product key, the supplier key and the quantitie. It's correct??

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    That's how I would do it, assuming that one product had only one supplier.

    -PatP

Posting Permissions

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