I'm testing Microsoft SQL Server, I want to check that how much time it takes when I perform a query.
Asked
Active
Viewed 185 times
3 Answers
2
In the query window place SQL like below:
SET STATISTICS TIME ON;
--Your Query Goes Here
SELECT * FROM Table
SET STATISTICS TIME OFF;

Khorshed Alam
- 314
- 2
- 11
1
Declare @startDate datetime
Declare @endDate datetime
begin
set @startDate=GETDATE()
select * from Table1
set @endDate=GETDATE()
select DATEDIFF(ms,@startDate,@endDate) as 'Execution Time '
/*
ms is for millisecond you can also use following argument
minute mi, n
second ss, s
millisecond ms
microsecond mcs
nanosecond ns
*/
end

Hitesh Thakor
- 471
- 2
- 12
-
better approach @ hitesh – Sunny Jangid Oct 31 '17 at 06:55
-
@SunnyJangid - No it isn't. It doesn't give you the breakdown of CPU and elapsed time and compile time and would also involve littering your code with timing statements that you then need to remove. – Martin Smith Oct 31 '17 at 07:57
0
DECLARE @EndT datetime
DECLARE @StartT datetime
SELECT @StartT=GETDATE()
-- Write Your Query
SELECT @EndT=GETDATE()
--This will return execution time of your query
SELECT DATEDIFF(ms,@StartT,EndT) AS [Execution Time in millisecs]
for more information About DATEDIFF See https://learn.microsoft.com/en-us/sql/t-sql/functions/datediff-transact-sql

Imran Ali Khan
- 8,469
- 16
- 52
- 77