如何知道TSQL语句已经运行了多久
Posted 阳光白云--davidhou
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何知道TSQL语句已经运行了多久相关的知识,希望对你有一定的参考价值。
如何知道TSQL语句已经运行了多久
declare @ms_per_tick decimal(10,6) --millisecond per tick SELECT @ms_per_tick=1.0*datediff(millisecond,sqlserver_start_time ,getdate())/(ms_ticks-sqlserver_start_time_ms_ticks) FROM sys.[dm_os_sys_info]; --SELECT @ms_per_tick select req.session_id,req.start_time request_start_time, ((select ms_ticks from sys.dm_os_sys_info)-workers.task_bound_ms_ticks )*@ms_per_tick ‘ms_since_task_bound‘,DATEDIFF(ms,req.start_time,getdate()) ‘ms_since_request_start‘, tasks.task_state,workers.state worker_state,req.status request_state,st.text, SUBSTRING(st.text, (req.statement_start_offset/2)+1, ((CASE req.statement_end_offset WHEN -1 THEN DATALENGTH(st.text) ELSE req.statement_end_offset END - req.statement_start_offset)/2) + 1) AS stmt ,qp.query_plan,req.* FROM sys.dm_exec_requests req LEFT join sys.dm_os_tasks tasks ON tasks.task_address=req.task_address LEFT join sys.dm_os_workers workers ON tasks.task_address=workers.task_address CROSS APPLY sys.dm_exec_sql_text(req.sql_handle) st CROSS APPLY sys.dm_exec_query_plan(req.plan_handle) qp where (req.session_id>50 or req.session_id is null) go
--转自 https://blogs.msdn.microsoft.com/apgcdsd/2011/05/05/tsql/
以上是关于如何知道TSQL语句已经运行了多久的主要内容,如果未能解决你的问题,请参考以下文章
TSQL 帮助 | INSERT 语句的选择列表包含的项目少于插入列表 [关闭]