K!

by Karl Bunyan

Programming, PHP, JavaScript, .Net, motorbikes, pubs, poker, football, news, restaurants and anything else

Facebook
http://twitter.com/karlbunyan

Friday, September 14, 2007

Identifying slow blocking queries on SQL Server

This piece of SQL is perfect for finding which query is running at any particular time, especially if you want to find what it is that's running very slowly.

sp_who2

This should return a list of what's running, including process ids (in the first column). Find out what's causing all the trouble and enter it's id after spid = below:

DECLARE @Handle binary(20)
SELECT @Handle = sql_handle FROM
  master.dbo.sysprocesses WHERE spid = 55
SELECT * FROM ::fn_get_sql(@Handle)

Link to this post

Comments:
Post a Comment

Recent posts in the Programming category

Archive

Other links

Change the background image