3 ms·
Don't mix transactions and locks. Transaction just ensures that all queries within it were run successfully and atomically. Locks are used to prevent race condi
by ivanhoe 7y ago
Don't mix transactions and locks. Transaction just ensures that all queries within it were run successfully and atomically. Locks are used to prevent race conditions. And in your particular example neither a transaction, nor lock would help, you need to check explicitly in UPDATE if you've got any books left.
- balfirevic 7y agoRace conditions absolutely are among the set of things transactions are supposed to help with and locks are one of the several ways they do it. It's the I from ACID, which stands for Isolation. Transactions are not omnipotent in that regard and they fail in several well-researched ways, but it is in their purview.