If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Don't know foreign key?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-15-07, 00:22
redarroweric redarroweric is offline
Registered User
 
Join Date: Jan 2007
Posts: 2
Question Don't know foreign key?

I have read many books and I think I am missing something.

How can I insert data in a table if I do not know the foreign key. I want to enter a new load in a trucking database. I know the shippers name although I do not know the ShipperId. Not sure how to write the query.

Loads
PK_LoadId
FK_ShipperId
PickUpDate
DeliverDate

SHIPPERS
PK_ShipperId
Name
Address
City
State
Reply With Quote
  #2 (permalink)  
Old 01-15-07, 03:48
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by redarroweric
I know the shippers name although I do not know the ShipperId. Not sure how to write the query.
Code:
select PK_ShipperId
  from SHIPPERS
 where Name = 'Todd''s Shipping'
then use that value in the INSERT statement for the Loads table
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-15-07, 04:23
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,246
that'd work.....

but can I ask how are you collecting this information and entering into the database?

If you do this through a form/data entry screen then you could set up a combo box that displays the Shipper Name to the user, but uses the ShipperID for the record.

have a look at using a combobox in what ever front end you are using.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton

Last edited by healdem; 01-15-07 at 04:27.
Reply With Quote
  #4 (permalink)  
Old 01-15-07, 08:32
redarroweric redarroweric is offline
Registered User
 
Join Date: Jan 2007
Posts: 2
I guess I was making it harder then it is.

Thank You.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On