Pessimistic lock in T-SQL(T-SQL 中的悲观锁)
问题描述
如果我在 MS SQL Server 中选择一行进行更新,并希望将其锁定直到我更新或取消,哪个选项更好:-
If i SELECT a row for updating in MS SQL Server, and want to have it locked till i either update or cancel, which option is better :-
1) 使用像 UPDLOCK 这样的查询提示2) 对事务使用 REPEATABLE READ 隔离级别3) 任何其他选项.
1) Use a query hint like UPDLOCK 2) Use REPEATABLE READ isolation level for the transaction 3) any other option.
谢谢,查克.
推荐答案
两者都不是.当您的用户输入数据时,您几乎不想让事务保持打开状态.如果您必须实现这样的悲观锁,人们通常会通过滚动他们自己的功能来实现.
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.
这篇关于T-SQL 中的悲观锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:T-SQL 中的悲观锁
基础教程推荐
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 在多列上分布任意行 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
