如何知道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/
时间: 2024-10-17 16:20:46