Is there a way to find the last executed queries for a specific database in SQL Server 2012? I am able to find them using SSMS, but I don’t want to use SQL Profiler if I don’t have too. This is the query I’ve used to get the complete list of last executed queries.
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
How should I change it to break it down by database?
Free Guide: Managing storage for virtual environments
Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!