|
-
November 19th, 2004, 05:08 AM
#1
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
-
November 19th, 2004, 06:00 AM
#2
Re: Inserting data into multiple tables
U can use View for insertion.
Best regards,
Krzemo.
-
November 19th, 2004, 06:04 AM
#3
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
-
November 19th, 2004, 06:14 AM
#4
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.
-
November 21st, 2004, 09:51 PM
#5
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..
-
November 22nd, 2004, 04:09 AM
#6
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
-
November 22nd, 2004, 04:12 AM
#7
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|