在 SQL Server 2008 中查找 SQL 锁的最佳方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7139561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best way to find SQL Locks in SQL Server 2008
提问by Gaurav Mittal
What is the best way to find the SQL locks along wih the user associated with that lock in SQL Server 2008?
在 SQL Server 2008 中找到与该锁关联的用户的 SQL 锁的最佳方法是什么?
回答by Remus Rusanu
select * from sys.dm_tran_locks
will list all current locks, granted or pending, along with the requesting session id. select * from sys.dm_exec_sessions
will list all current sessions, including the client host and login name. But going this way is very seldom what you want. For a more digestible form, use the Activity Monitorand watch the blocking as reported there.
select * from sys.dm_tran_locks
将列出所有当前的锁定,授予或挂起,以及请求会话 ID。select * from sys.dm_exec_sessions
将列出所有当前会话,包括客户端主机和登录名。但这种方式很少是你想要的。对于更易于理解的形式,请使用活动监视器并观察那里报告的阻塞。
回答by Carlos
Run this against the master db:
对主数据库运行这个:
SELECT spid,blocked,program_name,loginame,hostname,lastwaittype,*
FROM master.dbo.SysProcesses
WHERE blocked <> 0