且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

T-SQL中的悲观锁

更新时间:2023-02-05 23:25:09

都没有.用户输入数据时,您几乎永远都不希望打开事务.如果您要拥有这样的悲观锁,人们通常会通过滚动自己的功能来实现.

Neither. You almost never want to hold a transaction open while your user is inputting data. If you have to implement a pessimistic lock like this, people generally do it by rolling their own functionality.

请考虑您正在做的所有事情.我曾经在一个实现了像这样的锁定的系统上工作.您经常会遇到成堆的过时的锁,而当您将它们强加给用户时,他们很快就会感到困惑和愤怒.对于我们而言,解决方案是完全删除此锁定功能.

Consider the full ramifications of what you are doing. I once worked on a system that implemented locking like this. You often run into tons of stale locks, and your users get confused and angry very quickly when you foist this on them. The solution for us in our case was to remove this locking functionality entirely.