DMV that stores T-SQL Statements that have been executed

  • I now that in Oracle there is a table that stores SQL Statements that have been executed.

    Does SQL Server have a DMV that stores T-SQL Statements executed?

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • i believe this is only items that have a chached plan that was recently used; if the command is not in this, you'd have to add a trace to capture it in the future.

    SELECT DEST.TEXT

    FROM sys.[dm_exec_connections] SDEC

    CROSS APPLY sys.[dm_exec_sql_text](SDEC.[most_recent_sql_handle]) AS DEST

    --WHERE SDEC.[most_recent_session_id] = @spid

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • sys.dm_exec_query_stats will show you an aggregate of all the calls against the database for the queries still in cache. I suspect that's what you need.

    Otherwise, you can use sys.dm_exec_requests to see the calls that are currently executing.

    If you really need to monitor individual calls, I'd suggest setting up an extended events session to capture them out to a file.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply