How to know how long the TSQL statement has been running

Source: Internet
Author: User
Tags getdate

How to know how long the TSQL statement has been running
Declare @ms_per_tick decimal(Ten,6)--millisecond per tickSELECT @ms_per_tick=1.0*DateDiff(Millisecond,sqlserver_start_time,getdate())/(ms_ticks-sqlserver_start_time_ms_ticks) fromSys.[Dm_os_sys_info];--SELECT @ms_per_tickSelectReq.session_id,req.start_time Request_start_time, ((SelectMs_ticks fromsys.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,     (( CaseReq.statement_end_offset when -1  Then datalength(St.text)ELSEReq.statement_end_offsetEND -Req.statement_start_offset)/2)+ 1) asstmt, Qp.query_plan,req.* fromsys.dm_exec_requests req Left Joinsys.dm_os_tasks Tasks onTasks.task_address=req.task_address Left Joinsys.dm_os_workers Workers onTasks.task_address=workers.task_address CrossAPPLY sys.dm_exec_sql_text (req.sql_handle) St CrossAPPLY sys.dm_exec_query_plan (req.plan_handle) QPwhere(req.session_id> - orreq.session_id is NULL)Go

--Transfer from https://blogs.msdn.microsoft.com/apgcdsd/2011/05/05/tsql/

How to know how long the TSQL statement has been running

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.