View recently run queries in MSSQL 2005

Posted by Dan on Jan 3, 2008 @ 10:01 AM

Pinal Dave posted this great little SQL snippet to view most recent queries executed in SQL Server 2005.

    deqs.last_execution_time as [Time], dest.text as [Query]
    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

This is definitely a useful SQL snippet to see what's just happened when you're in a pinch.

Categories: SQL


  • Er. Looked cool. Thought i could use it. Tried it. Didn't have the access level on the SQL Server that I needed. :(

    Perhaps its because its been a while since i have developed in a MS SQL environment (used to Oracle), but some more explanation about *what* the query is doing would help me understand how MS SQL Server works.

    Still i copied the snippet into my SQL notebook. :)
  • @Bobby:

    You should only run this on a database you have access to. I'm not exactly sure what level of access you need in order to sys tables & stored procs. You might want to head over to Pinal Dave's post and ask the question there.
  • EXACTLY what I was looking for. Thanks SO much for taking the time to share this. My head feels wonderful now that I have stopped ponding it on the desk.....

  • ...Pounding Too...
  • Good work! Thank you

Add Comment

Leave this field empty