in reply to Locking a database connection
I'm confused. How can you read X from table A if it doesn't exist (assuming in step C you're going to write it to table A)? Or is step B "attempt to read X from table A"? Then I think the answer is to have a unique index on X in table A. You'll never have duplicate data.