I've got this script made by someone and I looked over it and found something I'm not sure is safe:
Inside a transaction there are 2 consecutive inserts, in 2 different tables, both with auto incremented primary keys. They are supposed to be the same (the primary key generated from the first insert = the primary key generated from the second insert).
Don't ask me why, it's just how the script was made.
I'm new to transactions and I can't quite figure out if there is a concurrency issue here. I am thinking about the possibility of another thread running in the same time and ending up with keys being generated something like:
Thread #1: Table_A ID: 3 Table_B ID: 4
Thread #2: Table_A ID: 4 Table_B ID: 3
I'm pretty sure (I've only ready transaction-related documentation today for the first time) that a transaction would not protect against this, but I just want to be sure I got it right.
Thanks!