CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2004
    Location
    London, England
    Posts
    563

    Question Inserting data into multiple tables

    I have setup a database in MS Access 2K that has several tables. There are several relationships that exists between tables. My question is this: If I insert a row of data in one table that stores foreign keys from other tables, how can I ensure that all tables concerned are updated using INSERT?

    For example, I have the main table :

    PK - Quote_id
    FK - Customer_ID
    Project_Name


    and the Customer table :

    PK - Customer_ID
    Customer_Name


    this is a 1:M relationship.

    Using a C# Form, I enter the data for Customer Name and the Project Name. Using the INSERT, how can I populate, not only the main table, but the Customer table too?

    At the moment I'm having to get the customer name and inserting that data into the Customer table then once the data has been inserted I get the new Customer_ID, using a SELECT. once I have the new Customer_ID, I then use that as part of my INSERT statement to populate the main table.

    Surely there must be a more effecient way to updating multiple tables that share a relationship?

    Regards

    John

  2. #2
    Join Date
    Nov 2004
    Location
    Poland
    Posts
    1,355

    Re: Inserting data into multiple tables

    U can use View for insertion.


    Best regards,
    Krzemo.

  3. #3
    Join Date
    May 2004
    Location
    London, England
    Posts
    563

    Re: Inserting data into multiple tables

    Thanx for the reply Krzemo. However, your answer is correct if I was using Access only, but I'm using the Access 2K database with a .Net interface, and Access does not allow for stored procedures, otherwise I could've done what u have suggested.

    Any other suggestions would be grateful.

    Regards

    John

  4. #4
    Join Date
    Nov 2004
    Location
    Poland
    Posts
    1,355

    Re: Inserting data into multiple tables

    I'm telling U only to use VIEW (not a Stored Procedure).

    Open "SELECT ... FROM tb1 INNER JOIN tb2 ..." etc
    And it should work (but I'm not using Access with .NET - only VB, C++, VBA)

    Best regards,
    Krzemo.

  5. #5
    Join Date
    Jul 2004
    Location
    Jakarta, Indonesia
    Posts
    596

    Re: Inserting data into multiple tables

    ..how can I ensure that all tables concerned are updated using INSERT?
    try using cascade Update Related Field when u build relations at Access..
    Last edited by erickwidya; November 22nd, 2004 at 04:10 AM. Reason: wrong quote..

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL

  6. #6
    Join Date
    Apr 2003
    Location
    Athens, Greece
    Posts
    1,094

    Re: Inserting data into multiple tables

    I think you need to separate INSERT statements anyway. There is no multitable insert. See the answer given to me in this thread
    Extreme situations require extreme measures

  7. #7
    Join Date
    Jul 2004
    Location
    Jakarta, Indonesia
    Posts
    596

    Re: Inserting data into multiple tables

    ..Using the INSERT, how can I populate, not only the main table, but the Customer table too?
    u must use SELECT to populate the record u want..
    not INSERT and u can use what Krzemo suggestion..INNER JOIN

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured