Insert of a new row by different users
409206Nov 17 2003 — edited Dec 4 2003I want to insert a row only if the row doesn't exist yet. So I look for the row in the table and, if I don't find it, I will insert it. But what if another client is doing the same thing and, in the time between my select and my insert, he inserts the row? To summarize:
transaction 1 (me):
TIME1:select ... where id=10;
TIME4:"if no rows"
����insert
trans2:
TIME2: select ... where id=10;
TIME3:"if no rows"
����insert
My insert (TIME4) will not work, even if I checked the existence of the row with the select (TIME1).
How can I avoid this?