SQL Server Diagnostic Information Queries for August 2013

I have gone through and made some minor updates and bug fixes for all of my SQL Server Diagnostic Information Queries for this month. I also added two new queries at the end of the script, to collect some information about the SQL Server Agent jobs and about the SQL Server Agent alerts (which are different than notifications about jobs) on the SQL Server instance.

Rather than having a separate blog post for each version, I’ll just put the links for all four versions here.

SQL Server 2005 Diagnostic Information Queries SQL Server 2005 Blank Results

SQL Server 2008 Diagnostic Information Queries SQL Server 2008 Blank Results

SQL Server 2008 R2 Diagnostic Information Queries SQL Server 2008 R2 Blank Results

SQL Server 2012 Diagnostic Information Queries SQL Server 2012 Blank Results

About half of the queries are instance specific and about half are database specific, so you will want to make sure you are connected to a database that you are concerned about instead of the master, system database.

The idea is that you would run each query in the set, one at a time (after reading the directions). You need to click on the top left square of the results grid to select all of the results, and then right-click and select “Copy with Headers” to copy all of the results, including the column headers to the Windows clipboard. Then you paste the results into the matching tab in the spreadsheet.

There are also some comments on how to interpret the results after each query. Please let me know what you think of these queries.

This entry was posted in Diagnostic Queries, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012 and tagged , . Bookmark the permalink.

15 Responses to SQL Server Diagnostic Information Queries for August 2013

  1. diegofarina says:

    Fantastic,all in one script,very useful thanks

  2. brenda says:

    The URLS do not work.

  3. Ajay Prakash says:

    Hi Glenn,

    Many thanks for your contributions on SQL server Diagnostic Information Queries. I was particularly looking at SQL Server 2008 R2 on https://sqlserverperformance.wordpress.com/ .

    The one that I could not understand was in section as below in which I am still to figure out the meaning and usage of column “running_pct”. I will appreciate if you could please explain a bit. Also not sure if you also want to add “DBMIRROR_DBM_MUTEX” into your NOT IN list, because this seems to be for information purpose only.

    — Isolate top waits for server instance since last restart or statistics clear (Query 23) (Top Waits)
    WITH Waits AS

    (SELECT wait_type, wait_time_ms / 1000. AS wait_time_s,
    100. * wait_time_ms / SUM(wait_time_ms) OVER() AS pct,
    ROW_NUMBER() OVER(ORDER BY wait_time_ms DESC) AS rn
    FROM sys.dm_os_wait_stats WITH (NOLOCK)
    SELECT W1.wait_type,
    CAST(W1.wait_time_s AS DECIMAL(12, 2)) AS wait_time_s,
    CAST(W1.pct AS DECIMAL(12, 2)) AS pct,
    CAST(SUM(W2.pct) AS DECIMAL(12, 2)) AS running_pct
    FROM Waits AS W1
    INNER JOIN Waits AS W2
    ON W2.rn <= W1.rn
    GROUP BY W1.rn, W1.wait_type, W1.wait_time_s, W1.pct
    HAVING SUM(W2.pct) – W1.pct < 99 OPTION (RECOMPILE); — percentage threshold


  4. Glenn,

    thank you for providing diagnostic queries for SQL Server.
    I found very useful columnstore diagnostic queries here: https://social.technet.microsoft.com/wiki/contents/articles/3540.sql-server-columnstore-index-faq.aspx#Managing_columnstore_indexes in section “How big are my columnstore indexes?” (of course this only applies to SQL Server 2012).

    What about adding them to your collection?

    Thanks, Klaus

  5. Jan Arnoldus says:

    Thank you very much for these helpful queries. I tried the 2008 version against my db and found the following problems. I wonder if you would kindly take a look at these messages.


    — Get CPU utilization by database (Query 16) (CPU Usage by Database)
    Msg 102, Level 15, State 1, Line 6 Incorrect syntax near ‘.’.

    — Find single-use, ad-hoc and prepared queries that are bloating the plan cache (Query 29) (Ad hoc Queries)
    Msg 321, Level 15, State 1, Line 3 “plan_handle” is not a recognized table hints option. If it is intended as a parameter to a table-valued function or to the CHANGETABLE function, ensure that your database compatibility mode is set to 90.

    — I/O Statistics by file for the current database (Query 31) (IO Stats By File)
    Msg 102, Level 15, State 1, Line 10 Incorrect syntax near ‘(‘.

    — Top cached queries by Execution Count (SQL Server 2008) (Query 32) (Query Execution Counts)
    Msg 102, Level 15, State 1, Line 8 Incorrect syntax near ‘.’.

    — Lists the top statements by average input/output usage for the current database (Query 40) (Top IO Statements)
    Msg 102, Level 15, State 1, Line 10 Incorrect syntax near ‘.’.

    — Find missing index warnings for cached plans in the current database (Query 43) (Missing Index Warnings)
    Msg 102, Level 15, State 1, Line 4 Incorrect syntax near ‘.’.

    — Get fragmentation info for all indexes above a certain size in the current database (Query 48) (Index Fragmentation)
    Msg 102, Level 15, State 1, Line 4 Incorrect syntax near ‘(‘.

  6. Richard says:


    Just tried out the 2005 version and found that the 2nd query didn’t retrieve anything. Found that I needed to add “OR loginname = ‘NT AUTHORITY\NETWORK SERVICE’ to the WHERE clause. Not sure why my sid doesn’t match, but mine shows 0x010100000000000514000000 instead of 0x010100000000000512000000.

    Also noticed that in the source comments, you referenced 2 different queries as Query 33 and 2 queries reference Query 37. Got confused while walking through the code to read comments and apply them against the result sets.

    Thanks for all the work that went into these queries.


  7. Michael Irwin says:

    Am I expecting more than I should? I click the link for SQL Server 2012 and get a download of an Excel xlsx workbook with lots of empty pages. Is this correct or am I missing something fundamental? !

    • Glenn Berry says:

      There are two links for SQL Server 2012 (and for every other version). The one on the left is the actual query script, and the one on the right (the one you clicked) is the blank results spreadsheet.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s