Lets say there are 3 users A,B,C hitting to the db and runs a update query at the same point of time(Not even a milisecond diff).
Example Scenario: Lets say we have a ref_Product_qty table which stores the product id and quantiy available in the warehouse.
Now we have a "Add to Cart" button on our site. When thousand of user will hit this button at the same time there is a sure possibility of overlapping and we have this query running behind.
if (qty > 0) {
UPDATE ref_Product_qry
SET qty = qty-1
WHERE productid = 12345
}
Now which user out of A/B/C will get the highest priority?
We can have many other similar kind of scenarios.
I have gone through both optimistic and pessimistic locking(Isolation levels) , But still I do not have the clear idea, How SQL Server prioritises the update/write request if they came at same time.
I know this is a very basic question , but i did not get a clear idea even after reading many blogs.Please help.