SQL SERVER – Recently Executed T-SQL Query

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)

About these ads

10 thoughts on “SQL SERVER – Recently Executed T-SQL Query

  1. 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

    Like

  2. 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

    Like

  3. 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

    Like

  4. 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.

    Like

  5. 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.

    Like

  6. Pingback: SQL SERVER – Weekly Series – Memory Lane – #051 | Journey to SQL Authority with Pinal Dave

  7. Hi Pinal,

    When a search expression is being run in GUI application, how to trace the corresponding query on SQL Server.

    Thanks in advance.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s