This tutorial proposes 3 ways in order for you to get the Execution time of SQL Query or Stored Procedures are called or submitted to your SQL Server.
They will give you durations in microseconds and base on the execution time, you may have a deeper understand and will do some optimization for your database structure/indexing to make it runs better.
1. Using SQL Server Profiler
I think it’s a easiest way for you to trace/track Which Stored Procedures Or SQL Commands Are Running On SQL Server and how long it takes for each of SQL Query/ Stored Procedure execution.
As you see, all commands are in TextData column and all Execution time for each are in Duration column respectively.
2. Using SQL Script with @StartTime and @EndTime parameters
The script should be run on SQL Server Management Studio Query.
1 2 3 4 5 6 7 8 9 10 11 12
USE AdventureWorksDW; GO DECLARE @StartTime datetime,@EndTime datetime SELECT @StartTime=GETDATE() SELECT * FROM DimCustomer WHERE Gender = 'M' SELECT @EndTime=GETDATE() SELECT DATEDIFF(ms,@StartTime,@EndTime) AS [Duration IN microseconds]
Just replace your own SQL statements with line 2, after execute the statement, it will show the Duration in microseconds in another result panel.
3. Using SQL Script with SET STATISTICS TIME (Transact-SQL)
It displays the number of milliseconds required to parse, compile, and execute each statement.
Run this SQL script on your SQL Query:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
USE AdventureWorksDW; GO SET STATISTICS TIME ON GO SELECT * FROM DimCustomer WHERE Gender = 'M'GO SET STATISTICS TIME OFF; GO [/SQL] AND below IS the RESULT SET: [text] SQL Server parse AND compile TIME: CPU TIME = 0 ms, elapsed TIME = 1 ms. SQL Server parse AND compile TIME: CPU TIME = 0 ms, elapsed TIME = 1 ms. (9351 ROW(s) affected) SQL Server Execution Times: CPU TIME = 63 ms, elapsed TIME = 479 ms. SQL Server parse AND compile TIME: CPU TIME = 0 ms, elapsed TIME = 1 ms.
That’s all! Feel free to contribute your own solution by submitting your comments as you’re always be welcome.