let's make an example
we have a web site for a car dealer, the db has two tables
1- Person with an auto-increment ID and other useless attributes (name,surname,...)
2- Car with an auto-increment ID and an attribute ownerID that is a foreign key references Person (plus other usuless attributes)
a new client comes in the car dealer and buy a new car, now what we do is:
1- create a row in Person table
2- create a row in Car table but we don't know what is the ownerID
so my idea to do this is:
1- create a row in Person table
2- select the last insert ID in Person
3-create the row in Car table
I make these 3 statements in one single commit, but I think there is the possibility to have another insert of a new user between statement 1 and 2 that brings me to select the wrong ID
how do I proceed?