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)

Advertisements
This entry was posted in Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s