Home » Topic » How can I get the query history in SQL Server?

How can I get the query history in SQL Server?

Andrew Jackson ~ Modified: October 31st, 2015 ~ ~ 1 Minute Reading

Home Forums How can I get the query history in SQL Server?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #877 Score: 0
    Andrew Jackson
    Moderator
    1 pt

    Is there a way I can get the query history in SQL Server?

    #879 Score: 0
    Stephen West
    Moderator
    4 pts

    Run this:

    SELECT  d.plan_handle ,
            d.sql_handle ,
            e.text
    
    FROM    sys.dm_exec_query_stats d
            CROSS APPLY sys.dm_exec_sql_text(d.plan_handle) AS e

    And filter output with
    WHERE text like '%something%'

    #880 Score: 0
    Lincoln Burrows
    Moderator
    16 pts

    If SQL Server hasn’t been restarted, then you may be able to find the query in the plan cache.

    SELECT t.[text]
    FROM sys.dm_exec_cached_plans AS p
    CROSS APPLY sys.dm_exec_sql_text(p.plan_handle) AS t
    WHERE t.[text] LIKE N'%something unique about your query%';
    

    You can Monitor SQL queries by SQL Profiler if you need it

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.