SQL Server上的命令历史

时间:2012-04-24 12:55:46

标签: sql-server tsql sql-server-2008-r2 logging

此查询为我提供了在SQL Server上执行的命令的历史记录:

Select *
From
(
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
) x

当我添加Where x.Query LIKE '%Insert%'时,我得到的结果不好(我认为这是因为交叉连接):

Select *
From
(
    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
) x
Where x.Query LIKE '%Insert%'

如何让交叉联接在SQL Server 2008 R2上正常运行?

1 个答案:

答案 0 :(得分:3)

我不确定你的意思是:“结果不好”,但这对我有用:

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(sql_handle) AS dest 
WHERE dest.TEXT LIKE '%Insert%'