Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Table relationship question 1

Status
Not open for further replies.

grx21

Programmer
Joined
Aug 3, 2001
Messages
45
Location
US
I have two related tables, the relationship is one-to-many.

Tbl.distributor: distributor_id, distributor_name, city, phone, email_address

Tbl.order: order_id, distributor_id, order_date, ship_method, ship_date, po_number

What I don’t understand is the following: After the distributor information has been inserted into the tbl.distributor how does the distributor_id end up in the order table as well?

--grx21
 
whenever a distributor places and order they do something to identify themselves....either log in or input a distributor id.

when the order is placed, the distributor_id is inserted into the order table with the rest of the order.

The only dumb questions are the ones that are never asked
 
twcman thanks for answering my question. What if i were to use two sql queries one to enter the initial distributor record such as:
INSERT INTO DISTRIBUTOR
(distributor_name, city, phone, email_address)
VALUES
('Joe Inc.', 'This City', '555-1212', 'thisemail@thisemail.com')

and then run another query to go ahead and enter the distributor_id in the order table to form the relationship between the two tables (tbl.distributor & tbl.order) although no orders have been placed just yet such as:
INSERT INTO ORDER
(DISTRIBUTOR_ID)
SELECT DISTRIBUTOR_ID
FROM DISTRIBUTOR
WHERE (DISTRIBUTOR_ID = DISTRIBUTOR_ID);

Would that pose any problems later when an order is placed?

--grx21
 
If no order has been placed then there is no reason to insert into the order table. Just do the insert into the distributor table and wait for the distributor to enter an order.
then all you do is query the distributor table for the distributor_id and insert into the order table. You would not want non-orders in the order table.

The only dumb questions are the ones that are never asked
 
Good point. Thanks for all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top