What SQL statements is currently Running

Source: Internet
Author: User
Tags what sql

-- what sql statements are currently running? Select  start_time, ' Duration (secs) '  = datediff (Ss,start_time, getdate ())  ,  [Spid] = session_id, ecid, [database] = db_name (Sp.dbid),  [User] =  nt_username, [status] = er.status, [wait] = wait_type, [individual  Query] = SUBSTRING  (qt.text,           ER.STATEMENT_START_OFFSET/2, (case when er.statement_end_offset = -1        then len (CONVERT (NVARCHAR (MAX),  qt.text))  * 2                 else er.statement_end_ offset end -                          &nbsP;   er.statement_start_offset)/2), [parent query] = qt.text, program =  program_name, Hostname, nt_domainFROM sys.dm_exec_requests erINNER JOIN  Sys.sysprocesses sp on er.session_id = sp.spidcross apply sys.dm_exec_sql_ Text (er.sql_handle) as qtwhere session_id > 50               -- ignore system spids. and session_id not in  (@ @SPID)      -- Ignore this  Current statement.and spid = 55order by 1 desc, 2

Run the above query against the target server, you can know what SQL statements is currently Running.

What SQL statements is currently 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.