• In your previous post http://www.sqlservercentral.com/Forums/Topic1469296-392-1.aspx I gave you allready a sample you can use to insert values into a table that has a foreign key relation to another table. This post is similar to your previous post. So if you adjust the code a bit, you can use it to insert into the tables from this post.

    The thing you need to take care of is that the value of the foreign_key fields you enter in the [travel_request] and/or [onward_journey] table, must allready exists in table [users] and/or [travel_request].

    -- insert values and search the "users_id" from the [users] table

    insert into travel_request

    select 2-- hard coded value

    , users_id-- value selected from [users] table

    , 500-- hard coded value

    , 'me'-- hard coded value

    from users

    where username = 'Ram'

    -- insert values and search the "request_id" from the [travel_request] table, belonging to a name selected from the [users] table

    insert into onward_journey

    select

    1-- hard coded value

    , request_id-- value selected from [travel_request] table

    , '20130703'-- hard coded value

    , 'LONDON'-- hard coded value

    , 'NEW YORK'-- hard coded value

    , 'plane'-- hard coded value

    from users

    inner join travel_request

    on users.users_id = travel_request.users_id

    where username = 'Ram'

    If you want your ID columns in the table to be automaticly increased, you should change these columns to IDENTIY columns. See http://msdn.microsoft.com/en-us/library/ms186775.aspx

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **