ITPub博客

首页 > 数据库 > SQL Server > SQL Server 查询历史执行的SQL语句

SQL Server 查询历史执行的SQL语句

原创 SQL Server 作者:胡田新 时间:2020-12-07 14:41:58 0 删除 编辑

user DB --在对应数据查询

go


SELECT st.text as sql_statement,

       qs.creation_time as plan_last_compiled,

       qs.last_execution_time as plan_last_executed,

       qs.execution_count as plan_executed_count,

       qp.query_plan

FROM sys.dm_exec_query_stats qs

CROSS APPLY sys.dm_exec_sql_text(qs.plan_handle) st

CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp


where convert(nvarchar(10),last_execution_time,120)='2020-11-30' --查询日期

and st.text like '%定义游标%'--自定义查询条件

order by total_elapsed_time/execution_count desc


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31486267/viewspace-2740013/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2017-08-30

  • 博文量
    19
  • 访问量
    26881