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.
这篇关于如何找出是什么锁定了我的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何找出是什么锁定了我的表?
基础教程推荐
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 无法解决整理冲突 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
