Which lock hints should I use (T-SQL)?

后端 未结 5 929
暖寄归人
暖寄归人 2020-12-13 20:45

I want to implement an atomic transaction like the following:

BEGIN TRAN A

SELECT id
FROM Inventory
WITH (???)
WHERE material_id = 25 AND quantity > 10

         


        
5条回答
  •  死守一世寂寞
    2020-12-13 21:15

    MSSQL:

    SELECT id
    FROM Inventory (UPDLOCK)
    WHERE material_id = 25 AND quantity > 10;
    
    http://www.devx.com/tips/Tip/13134
    



    By any chance you're interested with PostgreSQL:

    SELECT id
    FROM Inventory    
    WHERE material_id = 25 AND quantity > 10
    FOR UPDATE;
    

提交回复
热议问题