• 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