Programming, SQL Database

Get Recently Run Queries in MSSql Database

Generally when you have multiple users use one database and you have to verify some stored procedures or queries that have been run during some interval in such case you can easily run below query to find all queries so here is how to get recently run queries in MySQL database? :

SELECT deqs.last_execution_time AS [Time], dest.TEXT AS [Query]
FROM sys.dm_exec_query_stats AS deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
ORDER BY deqs.last_execution_time DESC

By running this query you can easily track all queries with time and exact statements that have been run by the database. Even you can easily track some scheduled jobs or services and confirm by verifying each.


Leave a Reply

Your email address will not be published. Required fields are marked *