[Go] Querying the details of SQL statements being executed by SQL Server

Source: Internet
Author: User

Contains the user name, the database in which the SQL statement was executed, the execution start time, the driver, the host name

SELECT [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_off Set =-1 Then LEN (CONVERT (NVARCHAR (MAX), Qt.text)) * 2 ELSE Er.statement_end_offset End-er.statem Ent_start_offset)/2),

[Parent Query] = Qt.text,

program = Program_name, Hostname,

Nt_domain, Start_time

From sys.dm_exec_requests er INNER JOIN sys.sysprocesses sp on er.session_id = sp.spid Cross APPLY sys.dm_ex Ec_sql_text (Er.sql_handle) as QT WHERE session_id >/* Ignore system spids.*/and session_id not in (@ @SPID)

[Go] Querying the details of SQL statements being executed by SQL Server

Related Article

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.