Jump to content
Weiss

Well..this cant be right

Recommended Posts

Hi. im almost sure im doing something terribly wrong... here goes: i have 2 tables, one for Customer (ID(primary)address,phone...etc..) and one for Order (OrderNumber(primary), order info, date of the order....etc) (both primary auto inc) both have foreign keys which point to the other tables primary key..

Now, when a new order is being made, i insert data to the Order table.... after that i need to insert data to the customer table... 

So... when i insert data to the order table, i cannot insert data to the foreign key column  since i do not know what will be the data inside the primary key column of the customer table. so, now the primary key data in a variable, and go to the customer table and insert the data of the customer and in the foreign key i spit out what was in the variable i saved earlier, after i run the sql command line i can see the id key that have been issued so i save that in a variable. so i have to go back to the order table and insert the data in the foreign key there and NOW i have data in the 2 tables which is connected thru the foreign keys.

this MUST be wrong there's no way im doing it right... right?

Share this post


Link to post
Share on other sites

Insert the customer first, then the order after. You should only need to insert once into each table.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...