Reputation: 74390
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:
Upvotes: 289
Views: 259226
Reputation: 209
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.
Upvotes: 16
Reputation: 111
Include Client Statistics by pressing Ctrl+Alt+S. Then you will have all execution information in the statistics tab below.
Upvotes: 5
Reputation: 161
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
Upvotes: 3
Reputation: 9812
Turn on Client Statistics by doing one of the following:
Then you get a new tab which records the timings, IO data and rowcounts etc for (up to) the last 10 exections (plus averages!):
Upvotes: 171
Reputation: 5708
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
Measuring Query Performance : "Execution Plan Query Cost" vs "Time Taken"
Upvotes: 26
Reputation: 61
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
Upvotes: 6
Reputation: 1194
I was struggling with that until i found this...
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...
Upvotes: 94
Reputation:
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.
Upvotes: 456