SQL SERVER queries the SQL statement being implemented _mssql

Source: Internet
Author: User
Tags microsoft sql server microsoft sql server 2005 session id
Specific actions:
Finds the owner of the currently blocked statement based on the SPID and blocked in the master.dbo.sysprocesses, and then uses DBCC INPUTBUFFER () to view the blocking statement.

Example:
Open three Query Analyzer A, B, C
Create a test table Testdia
Create Table testdia (ID int);
execute the following statement in a:
Begin Tran
Insert into Testdia Values (1);
execute the following statement in B:
Select * from Testdia
Current condition: No results displayed in B, display status as waiting
execute the following statement in C:
declare @spid int, @blocked int
Select top 1 @blocked = Blocked
From master.dbo.sysprocesses
where blocked > 0
DBCC InputBuffer (@blocked)

Technical Reference:
DBCC inputbuffer (Transact-SQL)
Displays the last statement sent from the client to a Microsoft SQL Server 2005 instance.
DBCC InputBuffer (session_id [, request_id])
[With NO_INFOMSGS]
session_id
The session ID associated with each active primary connection.
request_id
The request (batch) to search accurately in the current session.
The following query returns REQUEST_ID:
Copy Code
SELECT request_id
From sys.dm_exec_requests
WHERE session_id = @ @spidWITH
Enable the options you want to specify.
No_infomsgs
Cancels all informational messages for severity levels from 0 to 10.
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.