How SQL server decides the priority of a request?

て烟熏妆下的殇ゞ 提交于 2019-12-12 00:42:51

问题


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.

来源:https://stackoverflow.com/questions/30343800/how-sql-server-decides-the-priority-of-a-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!