Last executed queries for a specific database

后端 未结 1 1599
梦谈多话
梦谈多话 2020-11-29 17:54

I know how to get the last executed queries using the following SQL in SSMS -

SELECT deqs.last_execution_time AS [Time], dest.text AS [Query]
FROM sys.dm_exe         


        
相关标签:
1条回答
  • 2020-11-29 18:26

    This works for me to find queries on any database in the instance. I'm sysadmin on the instance (check your privileges):

    SELECT deqs.last_execution_time AS [Time], dest.text AS [Query], dest.*
    FROM sys.dm_exec_query_stats AS deqs
    CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
    WHERE dest.dbid = DB_ID('msdb')
    ORDER BY deqs.last_execution_time DESC
    

    This is the same answer that Aaron Bertrand provided but it wasn't placed in an answer.

    0 讨论(0)
提交回复
热议问题