Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL: How can I get the number of executed queries per database or hour or ...?

Is there any way to see how many queries are executed in like every hour, or per database / hour, or average number of queries on a day, or ...whatever is interesting?

Just for statistics.. I like numbers. I can't just start a trace with Sql Server Profiler, because the UI will crash when too many queries come by.

Does SQL keep track of some basic 'executed queries statistics' somewhere, or are there any tools I can use to get this information?

(I use SQL Server 2008 R2)

like image 236
Erik Dekker Avatar asked Mar 23 '12 15:03

Erik Dekker


People also ask

How do I get a count of queries in SQL?

In SQL, you can make a database query and use the COUNT function to get the number of rows for a particular group in the table. Here is the basic syntax: SELECT COUNT(column_name) FROM table_name; COUNT(column_name) will not include NULL values as part of the count.

How do you find query execution time?

Using Client StatisticsGo to Menu >> Query >> Select Include client Statistics. Execute your query. In the results panel, you can see a new tab Client Statistics. Go to the Client Statistics tab to see the execution time.

How do I find the number of transactions in SQL Server?

The COUNT() function returns the number of records returned by a select query. Note: NULL values are not counted.


1 Answers

This should work:

select * 
from sys.dm_os_performance_counters
where counter_name = 'Batch Requests/sec'

It actually returns the total Batch Requests. You poll this number periodically and then use this calculation:

ReqsPerSec = (curr.Value - prev.Value) / (curr.time - prev.time)
like image 75
RBarryYoung Avatar answered Oct 06 '22 19:10

RBarryYoung