Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a sales/ordering system in VB.NET and MS Access. I have a database consisting of 4 tables: tblOrders, tblOrderDetails, tblProducts and tblManufacturers. I may add more tables if/when I see necessary. These tables are copied from the Northwind sample database.

I assume the purpose of having the order details table is so that one order can have multiple products. If this is the case, when creating an order, what table needs to be written to first? I'm confused about how to write to both tblOrders and tblOrders details when confirming an order.

What I have tried:

I'm not sure what to do. There is a one to many relationship between the OrderID in tblOrders and tblOrderDetails. I'm thinking of writing to the order details table first as this would create a record in the order details table. Because the primary key in the Orders table cannot be left blank, am I correct in thinking it would automatically fill this in for me in the order details table?
Posted
Updated 21-May-18 17:49pm

1 solution

Thinking logically, you create details "for" an order, that means an order must exist for you to add any details to it. Technically, the PK in Orders table must be an FK in the details of the order and must be not nullable in both the tables stressing the fact that you need to insert in the table "tblOrders" before you start inserting in "tblOrderDetails".
Also, use of a transaction will ensure the integrity of the data for both of these tables.
 
Share this answer
 
Comments
Maciej Los 22-May-18 2:31am    
Logically ;)
GKP1992 22-May-18 2:54am    
:D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900