Thursday, November 1, 2012

HOW TO KNOW SQL QUERY EXECUTION TIME


--Track query execution time
DECLARE @EndTime   DATETIME
DECLARE @StartTime DATETIME
SET @StartTime = GETDATE()

--Query goes here
select * from My_Table

SET @EndTime = GETDATE()

PRINT 'StartTime = ' + CONVERT(VARCHAR(30),@StartTime,121)
PRINT '  EndTime = ' + CONVERT(VARCHAR(30),@EndTime,121)
PRINT ' Duration = ' + convert(varchar,DATEDIFF(ms, @StartTime, @EndTime))+' mill seconds'