Finding out most recent queries run on a specific database

Posted on

I found this useful script online to find out the queries run on a specific database.  This script is useful when you are trying to go back and find out what was ran on the database.


SELECT deqs.last_execution_time AS [Time], dest.text AS [Query], dest.*

FROM sys.dm_exec_query_stats AS deqs

CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest

WHERE dest.dbid = DB_ID(‘dbname’)

ORDER BY deqs.last_execution_time DESC




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s