Friday, 17 April 2015

Find Last Run Query in SQL Server


Find Last Run Query in SQL Server


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
--WHERE dest.dbid = DB_ID('nTireOfficeNew')
--where dest.TEXT like '%select min(convert(%'
ORDER BY deqs.last_execution_time DESC

SELECT conn.session_id, sson.host_name, sson.login_name,
 sqltxt.text, sson.login_time,  sson.status
FROM sys.dm_exec_connections conn
INNER JOIN sys.dm_exec_sessions sson
ON conn.session_id = sson.session_id
CROSS APPLY sys.dm_exec_sql_text(most_recent_sql_handle) AS sqltxt
WHERE sqltxt.dbid = DB_ID('nTireOfficeNew')
ORDER BY sson.login_time desc

No comments:

Post a Comment