Thursday, January 8, 2015

SQL Script to find the last executed commands on the SQl Server

Sometimes we needs to find out the last executed commands on the database server. 
Below is the SQL script share by one of my friend Ken Watson to find out the last executed queries.

SELECT usecounts, cacheobjtype, objtype, text 
FROM sys.dm_exec_cached_plans 
CROSS APPLY sys.dm_exec_sql_text(plan_handle) 
WHERE usecounts > 1 
ORDER BY usecounts DESC; 



About Ken
He is working as SQL DBA. 
Blog:-  interflextech.com/blog
Twitter:- @interflextech

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete

  2. Nice Article !

    Really this will help to people of SQL Server Community.
    I have also prepared small note on this, Script to find last executed query in SQL Server.

    http://www.dbrnd.com/2015/11/sql-server-script-to-find-the-last-executed-query-using-spid/

    ReplyDelete