Results 1 to 4 of 4
  1. #1
    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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    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.
    Last edited by healdem; 01-15-07 at 05:27.
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Jan 2007
    Posts
    2
    I guess I was making it harder then it is.

    Thank You.

Posting Permissions

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