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?