SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


What SQL Statements Are Currently Executing?


What SQL Statements Are Currently Executing?

Author
Message
chinn
chinn
SSC Veteran
SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)

Group: General Forum Members
Points: 274 Visits: 707
This is very Useful..
Thanks Very Much!



dhayes-797480
dhayes-797480
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 9
I got that same message when trying this script on a SQL2000 server. This script is only for SQL2005.
Royce Powers
Royce Powers
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 20
That explains it! Thanks!
o-3463522
o-3463522
Grasshopper
Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)

Group: General Forum Members
Points: 13 Visits: 144
How to change the compatibility mode?
Jamie Pick
Jamie Pick
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 67
This is great. It will be very useful in nailing down those sneaky, long running processes that you can't get a peek at with the standard tools. Thanks!
Adam Gojdas
Adam Gojdas
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 1441
You will need 'VIEW SERVER STATE' permission to run the query that is in the proc.
Raj Gujar
Raj Gujar
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 Visits: 175
This was a good one , Helped me quite a bit.
timothyawiseman
timothyawiseman
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1460 Visits: 920
Very nice article and very useful query.

Just out of curiosity, why did you decide to make it a procedure instead of a view?

Naturally you would lose that order by, but since you may wish to see it ordered by other things such as User or Status anyway it seems the view would be more flexible.

---
Timothy A Wiseman
SQL Blog: http://timothyawiseman.wordpress.com/
ianstirk
ianstirk
SSC Veteran
SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)SSC Veteran (218 reputation)

Group: General Forum Members
Points: 218 Visits: 1037
Hi,

I’m glad you liked the article, it’s quite interesting to see what is happening with SQL Server and SQL.

I hadn’t really thought about creating a view, I typically create utilities as procedures by default, but maybe the advantages of permissioning and sorting make a view more appropriate…

Thanks
Ian
Adam Gojdas
Adam Gojdas
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 1441
I am planning on using a bit of a modified version that will filter to a specific DB. As a developer I am in need of just seeing what is on the DB I am working on. Here is a crack at a revision to the code to allow this.


IF OBJECT_ID(N'[dbo].[dba_WhatSQLIsExecuting]') IS NULL
BEGIN
EXEC ('CREATE PROCEDURE
[dbo].[dba_WhatSQLIsExecuting]
AS BEGIN SELECT ''STUB'' END');
END;
GO
ALTER PROC [dbo].[dba_WhatSQLIsExecuting]
--Inputs
@specificDB nvarchar(128) = NULL
AS
/*--------------------------------------------------------------------
Purpose: Shows what individual SQL statements are currently executing.
----------------------------------------------------------------------
Parameters: None.
Revision History:
24/07/2008 Ian_Stirk@yahoo.com Initial version
28/10/2008 added filter for a specific DB
Example Usage:
To get data from all DBs on that instance
1. exec YourServerName.master.dbo.dba_WhatSQLIsExecuting

To get data from a specific DB
2. DECLARE @thisDB nvarchar(128); SET @thisDB = DB_NAME();
exec YourServerName.master.dbo.dba_WhatSQLIsExecuting @thisDB
---------------------------------------------------------------------*/
BEGIN
DECLARE @thisSPID int;

SET @thisSPID = @@SPID;
-- Do not lock anything, and do not get held up by any locks.
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

-- What SQL Statements Are Currently Running?
SELECT
session_Id [SPID]
,ecid [ecid]
,DB_NAME(sp.dbid) [Database]
,nt_username [User]
,er.status [Status]
,wait_type [Wait]
,SUBSTRING (qt.text,
er.statement_start_offset/2,
(CASE WHEN er.statement_end_offset = -1
THEN LEN(CONVERT(nvarchar(max), qt.text)) * 2
ELSE er.statement_end_offset END -
er.statement_start_offset)/2)
[Individual Query]
,qt.text [Parent Query]
,program_name [Program]
,Hostname
,nt_domain
,start_time
FROM sys.dm_exec_requests [er]
INNER JOIN
sys.sysprocesses [sp]
ON er.session_id = sp.spid
CROSS APPLY
sys.dm_exec_sql_text(er.sql_handle) [qt]
WHERE session_Id > 50 -- Ignore system spids.
AND session_Id NOT IN (@thisSPID) -- Ignore this current statement.
--when a specific DB is supplied filter for it, ohterwise get all DBs
AND CASE WHEN @specificDB IS NULL THEN N'' ELSE DB_NAME(sp.dbid) END
= CASE WHEN @specificDB IS NULL THEN N'' ELSE @specificDB END
ORDER BY session_Id, ecid
END


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search