Home
> Uncategorized > Timing SQL statements
Timing SQL statements
Often, when comparing two SQL statements for speed, you end up relying on the counter in the bottom left counter of SQL Management studio,
but if you’re trying to shave milliseconds off a query that takes under a second than the result "00:00:00" doesn’t give you anything to go on.
but if you’re trying to shave milliseconds off a query that takes under a second than the result "00:00:00" doesn’t give you anything to go on.
So; instead, if you declare a @timeStart as a datetime, run your query, then get a datediff in milliseconds against the current time, then you get something more meaningful.
declare @timeStart as datetime
set @timeStart = getdate()
select count(*) from foo
select datediff(ms,@timestart,getdate())
In the above code block "select count(*) from foo" is the query I want to test.
Categories: Uncategorized
Comments (0)
Trackbacks (0)
Leave a comment
Trackback