SQL Check Locks

Scripts to Check locking issues in SQL server

1
2
3
4
  USE Master;
  GO;
  EXEC sp_who2;
  GO;

Which processes are blocked ?

1
2
3
4
5
6
  USE Master;
  GO;
  SELECT * 
  FROM sys.dm_exec_requests
  WHERE blocking_session_id <> 0;
  GO;

Which Processes are waiting for ressources ?

1
2
3
4
5
6
  USE Master;
  GO;
  SELECT session_id, wait_duration_ms, wait_type, blocking_session_id 
  FROM sys.dm_os_waiting_tasks 
  WHERE blocking_session_id <> 0;
  GO;