Home > Tips N Tricks > Monitor T SQL Query performance at millisecond level

Monitor T SQL Query performance at millisecond level

Many times upon executing any T-SQL queries, we like to know the performance of the query at millisecond level. But SSMS provides us information at second level as below:

SELECT *
FROM   Purchasing.vVendor;

You will see this value “00:00:00” coming at right-bottom side of Query Window. The value indicates that the query took zero second to execute, but actually it means it took less than 1 second. And moreover, someone might be interested in tracking the number of logical or physical reads happening when the query executes.

 So, in order to monitor the exact compile time and execution time for a given query in T-SQL, enable the below options in SSMS. Navigate to Tools » Options » Query Execution » SQL Server » Advanced. Remember to close all query windows before configuring otherwise it will not reflect in the current query window.

 

But in order to reflect the changes in the current query window, right click anywhere on the query window and click on “Query Options…

 

And in the dialog box, navigate to “Execution » Advanced” and enable “SET STATISTICS TIME” and “SET STATISTICS IO”.

Execute any query now:

SELECT *
FROM   Purchasing.vVendor;

OUTPUT (Click on “Messages” in output window):

Executing a view or procedure will also return the tables hit underneath the query along with the number of “logical reads” and “physical reads” happened at the table level.

Although this information is helpful but I would suggest to go for Query execution plan and SQL server profiler for serious optimization of queries.

To get a quick glance on the elapsed time for a bunch of queries, simply press “F4” to get Properties Window and you will get the necessary information. But here the elapsed time also includes connection time, printing results to output window, etc.

 

Waiting for your valuable comments. ☺ :)





Categories: Tips N Tricks
  1. rajat
    September 25th, 2011 at 22:28 | #1

    Nice tip.

  2. Ravi
    September 29th, 2011 at 17:01 | #2

    super like…

  3. ravikumar s
    November 10th, 2011 at 17:45 | #3

    really wonderful article Arun.

  4. Jayne
    November 24th, 2011 at 19:21 | #4

    Cool tip, whats the additional overhead in terms writing to the log file.

  5. pg
    June 16th, 2012 at 19:10 | #5

    Isn’t this information in the ‘Properties’ window?

  6. pg
    June 16th, 2012 at 19:10 | #6

    oh wait – just read it properly this time oops!

  7. January 3rd, 2013 at 21:44 | #7

    Congratulations.

    This tip very nice.

    Regards.

  1. No trackbacks yet.