| title | DBCC INPUTBUFFER (Transact-SQL) | Microsoft Docs | |||||
|---|---|---|---|---|---|---|
| ms.custom | ||||||
| ms.date | 7/16/2017 | |||||
| ms.prod | sql-non-specified | |||||
| ms.reviewer | ||||||
| ms.suite | ||||||
| ms.technology |
|
|||||
| ms.tgt_pltfrm | ||||||
| ms.topic | language-reference | |||||
| f1_keywords |
|
|||||
| dev_langs |
|
|||||
| helpviewer_keywords |
|
|||||
| ms.assetid | a44d702b-b3fb-4950-8c8f-1adcf3f514ba | |||||
| caps.latest.revision | 51 | |||||
| author | JennieHubbard | |||||
| ms.author | jhubbard | |||||
| manager | jhubbard |
[!INCLUDEtsql-appliesto-ss2008-xxxx-xxxx-xxx_md]
Displays the last statement sent from a client to an instance of [!INCLUDEmsCoName] [!INCLUDEssNoVersion].
Transact-SQL Syntax Conventions
DBCC INPUTBUFFER ( session_id [ , request_id ])
[WITH NO_INFOMSGS ] session_id
Is the session ID associated with each active primary connection.
request_id
Is the exact request (batch) to search for within the current session.
The following query returns request_id:
SELECT request_id
FROM sys.dm_exec_requests
WHERE session_id = @@spid; WITH
Enables options to be specified.
NO_INFOMSGS
Suppresses all informational messages that have severity levels from 0 through 10.
DBCC INPUTBUFFER returns a rowset with the following columns.
| Column name | Data type | Description |
|---|---|---|
| EventType | nvarchar(30) | Event type. This could be RPC Event or Language Event. The output will be No Event when no last event was detected. |
| Parameters | smallint | 0 = Text 1- n = Parameters |
| EventInfo | nvarchar(4000) | For an EventType of RPC, EventInfo contains only the procedure name. For an EventType of Language, only the first 4000 characters of the event are displayed. |
For example, DBCC INPUTBUFFER returns the following result set when the last event in the buffer is DBCC INPUTBUFFER(11).
EventType Parameters EventInfo
-------------- ---------- ---------------------
Language Event 0 DBCC INPUTBUFFER (11)
(1 row(s) affected)
DBCC execution completed. If DBCC printed error messages, contact your system administrator. On [!INCLUDEssNoVersion] requires one of the following:
- User must be a member of the sysadmin fixed server role.
- User must have VIEW SERVER STATE permission.
- session_id must be the same as the session ID on which the command is being run. To determine the session ID execute the following query:
SELECT @@spid; On [!INCLUDEssSDS] Premium Tiers requires the VIEW DATABASE STATE permission in the database. On [!INCLUDEssSDS] Standard and Basic Tiers requires the [!INCLUDEssSDS] admin account.
The following example runs DBCC INPUTBUFFER on a second connection while a long transaction is running on a previous connection.
CREATE TABLE dbo.T1 (Col1 int, Col2 char(3));
GO
DECLARE @i int = 0;
BEGIN TRAN
SET @i = 0;
WHILE (@i < 100000)
BEGIN
INSERT INTO dbo.T1 VALUES (@i, CAST(@i AS char(3)));
SET @i += 1;
END;
COMMIT TRAN;
--Start new connection #2.
DBCC INPUTBUFFER (52);