Counter of Festivals

Ashok Blog for SQL Learners and Beginners and Experts

Monday, 20 February 2012

-------------To know the last running query from SQL Server 2005 Database--------------------------------
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
ORDER BY sson.login_time desc,conn.session_id