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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×