如下所示:
BEGIN TRAN A
SELECT id
FROM Inventory
WITH (???)
WHERE material_id = 25 AND quantity > 10
/*
Process some things using the inventory record and
eventually write some updates that are dependent on the fact that
that specific inventory record had sufficient quantity (greater than 10).
*/
COMMIT TRAN A
问题是,还有其他事务正在发生,消耗了我们库存中的数量,所以从选择记录到在事务A中写入更新之间,该记录可能会成为无效选择,因为它的数量可能已经降低到WHERE子句中的阈值以下。