Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate execution time of a SQL query?

I am providing search functionality in my website, when user searches a record then I want to display the time the query taken to get the results same as google does. When we search anything then google displays how much time it takes to get results?

For this I have declared a @start variable in my SP and finding the difference in the end, as below;

DECLARE @start_time DATETIME  SET @start_time = GETDATE()  -- my query SELECT * FROM @search_temp_table  SELECT RTRIM(CAST(DATEDIFF(MS, @start_time, GETDATE()) AS CHAR(10))) AS 'TimeTaken' 

Is there any other easy and fast way, or a single line of query with which we can find out the time a query taken to execute?

I'm using SQL Server 2005.

like image 474
djmzfKnm Avatar asked Feb 27 '09 17:02

djmzfKnm


People also ask

How does MySQL calculate query execution time?

Now, go to the Scalyr dashboard menu and select MySQL. You will be able to see the log details of your MySQL, which includes the query time. This is a very simple and easy way to measure query time for a large number of MySQL queries.

How do you know the time taken to execute a query in Oracle?

Answer: For seeing the elapsed time for an individual query, you can see individual query response time in SQL*Plus with the "set timing on" command. For DBA's, Oracle has several tools for measuring system-wide response time using v$sysmetric, v$active_session_history, v$sqlarea and v$sysmetric_summary.

How do you find time intervals in SQL?

MySQL TIMEDIFF() Function The TIMEDIFF() function returns the difference between two time/datetime expressions. Note: time1 and time2 should be in the same format, and the calculation is time1 - time2.


1 Answers

Well, If you really want to do it in your DB there is a more accurate way as given in MSDN:

SET STATISTICS TIME ON 

You can read this information from your application as well.

like image 102
Faiz Avatar answered Sep 21 '22 20:09

Faiz