About a year ago, I wrote blog post about SQL SERVER – 2005 – Last Ran Query – Recently Ran Query. Since, then I have received many question regarding how this is better than fn_get_sql() or DBCC INPUTBUFFER.
The Short Answer in is both of them will be deprecated.
Please refer to following update query to recently executed T-SQL query on database.
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
ORDER BY deqs.last_execution_time DESC
Reference : Pinal Dave (http://blog.SQLAuthority.com)












Hi Pinal,
I ran this query it resulted with so many records.bit confusing. can you please let me know whats this query do?
Regards
Sanjeev Kumar
hi,
i tried above query i am getting output but i am not understanding output .
plz let me know in the query deqs means …..
Advance Thanks,
Rama krishna
hi ,
i have one dought about exception handling in sql server 2005,
i.e, if any error find in try block , is error display in front end or not
Hi Dave,
i wanted the recently executed query with user details with it. Is it possible that i can get these details.
please help me out.
Could we get the username also, who has executed what?
Hi Pinal,
How to give specific access permission to different windows account to access to SQL Server. Suppose i have ‘india-2348\test’ windows a/c, i am going to login with test windows a/c. But whatever permission i have given in administrator a/c i.e. user can not insert data into the student table, but he can select(read) the student table. this permission is for ‘india-2348\test’ a/c. so, no one can insert record in student table, but can read data from student table. plz help me out…
Thanks in advanced.