SQL Server Management Studio, how to get execution time down to milliseconds

Sql ServerSsmsSql Server-2008

Sql Server Problem Overview


When I submit a batch (e.g., perform a query) in SSMS, I see the time it took to execute in the status bar. Is it possible to configure SSMS to show the query time with millisecond resolution?

Here is the bar I am talking about with the section of interest circled in red:

enter image description here

Sql Server Solutions


Solution 1 - Sql Server

What you want to do is this:

set statistics time on

-- your query

set statistics time off

That will have the output looking something like this in your Messages window:

> SQL Server Execution Times: CPU time = 6 ms, elapsed time = 6 ms.

Solution 2 - Sql Server

Turn on Client Statistics by doing one of the following:

  • Menu: Query > Include client Statistics
  • Toolbar: Click the button (next to Include Actual Execution Time)
  • Keyboard: Shift-Alt-S

Then you get a new tab which records the timings, IO data and rowcounts etc for (up to) the last 10 exections (plus averages!):

enter image description here

Solution 3 - Sql Server

I was struggling with that until i found this...

http://blog.sqlauthority.com/2009/10/01/sql-server-sql-server-management-studio-and-client-statistics/

Also, if you open the Properties window you may find some magical "Connection elapsed time" that may give you some execution time... Hope it helps...

Solution 4 - Sql Server

To get the execution time as a variable in your proc:

DECLARE @EndTime datetime
DECLARE @StartTime datetime 
SELECT @StartTime=GETDATE() 

-- Write Your Query


SELECT @EndTime=GETDATE()

--This will return execution time of your query
SELECT DATEDIFF(ms,@StartTime,@EndTime) AS [Duration in millisecs] 

AND see this

https://stackoverflow.com/questions/564717/measuring-query-performance-execution-plan-query-cost-vs-time-taken/18974538#18974538

Solution 5 - Sql Server

I was after the same thing and stumbled across the following link which was brilliant:

http://www.sqlserver.info/management-studio/show-query-execution-time/

It shows three different ways of measuring the performance. All good for their own strengths. The one I opted for was as follows:


DECLARE @Time1 DATETIME

DECLARE @Time2 DATETIME

SET @Time1 = GETDATE()

-- Insert query here

SET @Time2 = GETDATE()

SELECT DATEDIFF(MILLISECOND,@Time1,@Time2) AS Elapsed_MS


This will show the results from your query followed by the amount of time it took to complete.

Hope this helps.

Solution 6 - Sql Server

I don't know about expanding the information bar.

But you can get the timings set as a default for all queries showing in the "Messages" tab.

When in a Query window, go to the Query Menu item, select "query options" then select "advanced" in the "Execution" group and check the "set statistics time" / "set statistics IO" check boxes. These values will then show up in the messages area for each query without having to remember to put in the set stats on and off.

You could also use Shift + Alt + S to enable client statistics at any time

Solution 7 - Sql Server

You can try this code:

USE AdventureWorks2012;
GO
SET STATISTICS TIME ON;
GO
SELECT ProductID, StartDate, EndDate, StandardCost 
FROM Production.ProductCostHistory
WHERE StandardCost < 500.00;
GO
SET STATISTICS TIME OFF;
GO

Solution 8 - Sql Server

Include Client Statistics by pressing Ctrl+Alt+S. Then you will have all execution information in the statistics tab below.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichael GoldshteynView Question on Stackoverflow
Solution 1 - Sql Serveruser596075View Answer on Stackoverflow
Solution 2 - Sql ServerNickGView Answer on Stackoverflow
Solution 3 - Sql ServerYmagine FirstView Answer on Stackoverflow
Solution 4 - Sql ServerMohammad Atiour IslamView Answer on Stackoverflow
Solution 5 - Sql ServerJ-ManView Answer on Stackoverflow
Solution 6 - Sql ServerlukeView Answer on Stackoverflow
Solution 7 - Sql ServerRohitkumarView Answer on Stackoverflow
Solution 8 - Sql ServerashiqsView Answer on Stackoverflow