title: Last executed queries for a specific database
body: <p>I know how to get the last executed queries using the following SQL in SSMS -</p>
  
  <pre><code>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
  </code></pre>
  
  <p>But I want to find them for a specific database. I don't want to use SQL Profiler, if I don't have to. Plus I don't think SQL Profiler will allow me to view queries that were already run without profiling turned on. I need to do this from SSMS.</p>