How to find out what is locking my tables?(如何找出是什么锁定了我的表?)
问题描述
我有一个 SQL 表突然无法返回数据,除非我在末尾包含 with (nolock)
,这表明我的表上留下了某种锁.
I have a SQL table that all of a sudden cannot return data unless I include with (nolock)
on the end, which indicates some kind of lock left on my table.
我已经对 sys.dm_tran_locks 来识别表上实际上有许多锁,但是我如何识别什么 正在锁定它们(即 sys.dm_tran_locks)?
I've experimented a bit with sys.dm_tran_locks to identify that there are in fact a number of locks on the table, but how do I identify what is locking them (ie the request element of the sys.dm_tran_locks)?
我知道 sp_lock 用于 SQL 2005 之前的版本,但现在该 sp 已被弃用,AFAIK 正确的方法是使用 sys.dm_tran_locks.我正在使用 SQL Server 2008 R2.
I know about sp_lock for pre SQL 2005, but now that that sp is deprecated, AFAIK the right way to do this is with sys.dm_tran_locks. I'm using SQL Server 2008 R2.
推荐答案
看看下面的系统存储过程,你可以在SQLServer Management Studio (SSMS)中运行:
Take a look at the following system stored procedures, which you can run in SQLServer Management Studio (SSMS):
- sp_who
- sp_lock
另外,在 SSMS 中,您可以通过不同的方式查看锁和进程:
Also, in SSMS, you can view locks and processes in different ways:
不同版本的 SSMS 将活动监视器放在不同的位置.例如,当您右键单击服务器节点时,SSMS 2008 和 2012 会将其显示在上下文菜单中.
Different versions of SSMS put the activity monitor in different places. For example, SSMS 2008 and 2012 have it in the context menu when you right-click on a server node.
这篇关于如何找出是什么锁定了我的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何找出是什么锁定了我的表?


- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01