0

Is there anyway to tell when the last query was made against a SQL 2008 R2 database without downloading a third-party tool ?

0

1 Answer 1

0

You can use the following SQL command to get the last commands that executed on MyDB (as example).

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('MyDB') --note you need to change MyDB to your database name
ORDER BY deqs.last_execution_time DESC

Usfull links:

https://stackoverflow.com/questions/13638435/last-executed-queries-for-a-specific-database

http://blog.sqlauthority.com/2008/01/03/sql-server-2005-last-ran-query-recently-ran-query/

http://blog.sqlauthority.com/2009/07/19/sql-server-get-last-running-query-based-on-spid/

Not the answer you're looking for? Browse other questions tagged or ask your own question.