SQL: How can I get the number of executed queries per database or hour or ...?
This should work:
select * from sys.dm_os_performance_counterswhere 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)
I am actually just learning about this in my Microsoft Certification.
Though I can't answer your question directly yet, I can send you in the right direction with a couple things:
- Have a look at the views inside the Server > Databases > System Databases > MSDB > Views > System Views. MSDN Systsem Views
- Have a look at the views inside the Server > Databases > System Databases > Master > Views > System Views.
- Take a peak at the trace tools available to SQL Server.
In the views note that you may actually have to join a couple of the views together or get at the underlying tables to get specifically what you are after.