适用对象:是SQL Server 是Azure SQL 数据库 否Azure Synapse Analytics (SQL DW) 否并行数据仓库APPLIES TO: yesSQL Server yesAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

显示从客户端发送到 MicrosoftMicrosoft SQL ServerSQL Server 实例的最后一个语句。Displays the last statement sent from a client to an instance of MicrosoftMicrosoft SQL ServerSQL Server.

主题链接图标 TRANSACT-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions


DBCC INPUTBUFFER ( session_id [ , request_id ])  


与各活动主连接关联的会话 ID。Is the session ID associated with each active primary connection.

request_id request_id
要在当前会话中搜索的精确请求(批)。Is the exact request (batch) to search for within the current session.

下面的查询返回 request_id :The following query returns request_id:

SELECT request_id   
FROM sys.dm_exec_requests   
WHERE session_id = @@spid;  

启用要指定的选项。Enables options to be specified.

取消严重级别从 0 到 10 的所有信息性消息。Suppresses all informational messages that have severity levels from 0 through 10.

结果集Result Sets

DBCC INPUTBUFFER 返回包含如下列的行集。DBCC INPUTBUFFER returns a rowset with the following columns.

列名Column name 数据类型Data type 描述Description
EventTypeEventType nvarchar(30)nvarchar(30) 事件类型。Event type. 这可能是 RPC 事件或 Language 事件 。This could be RPC Event or Language Event. 检测不到上一个事件时,输出为 No Event 。The output will be No Event when no last event was detected.
参数Parameters smallintsmallint 0 = 文本0 = Text

1- n = Parameters 1- n = Parameters
EventInfoEventInfo nvarchar(4000)nvarchar(4000) 对于 RPC 的 EventType,EventInfo 仅包含过程名 。For an EventType of RPC, EventInfo contains only the procedure name. 对于 Language 的 EventType,仅显示事件的前 4000 个字符 。For an EventType of Language, only the first 4000 characters of the event are displayed.

例如,当缓冲区中的最后一个事件是 DBCC INPUTBUFFER(11) 时,DBCC INPUTBUFFER 将返回以下结果集。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.  


SQL Server 2014 (12.x)SQL Server 2014 (12.x) SP2 开始,使用 sys.dm_exec_input_buffer 返回有关提交到 SQL ServerSQL Server 实例的语句的信息。Starting with SQL Server 2014 (12.x)SQL Server 2014 (12.x) SP2, use sys.dm_exec_input_buffer to return information about statements submitted to an instance of SQL ServerSQL Server.


对于 SQL ServerSQL Server,要求具有下列权限之一:On SQL ServerSQL Server requires one of the following:

  • 用户必须是 sysadmin 固定服务器角色的成员 。User must be a member of the sysadmin fixed server role.
  • 用户必须具有 VIEW SERVER STATE 权限。User must have VIEW SERVER STATE permission.
  • session_id 必须与正在运行该命令的会话 ID 相同 。session_id must be the same as the session ID on which the command is being run. 要确定会话 ID,请执行以下查询:To determine the session ID execute the following query:
SELECT @@spid;  

对于 SQL 数据库SQL Database 高级层和业务关键层,需要数据库的 VIEW DATABASE STATE 权限。On SQL 数据库SQL Database Premium and Business Critical tiers requires the VIEW DATABASE STATE permission in the database. 对于 SQL 数据库SQL Database 标准层、基本层和常规用途层,需要 SQL 数据库SQL Database 管理员帐户。On SQL 数据库SQL Database Standard, Basic, and General Purpose tiers requires the SQL 数据库SQL Database admin account.


以下示例在一个连接上运行一个时间较长的事务,而与此同时在另一个连接上运行 DBCC INPUTBUFFERThe 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));  
DECLARE @i int = 0;  
SET @i = 0;  
WHILE (@i < 100000)  
INSERT INTO dbo.T1 VALUES (@i, CAST(@i AS char(3)));  
SET @i += 1;  
--Start new connection #2.  

另请参阅See Also

DBCC (Transact-SQL)DBCC (Transact-SQL)
sp_who (Transact-SQL)sp_who (Transact-SQL)
sys.dm_exec_input_buffer (Transact-SQL)sys.dm_exec_input_buffer (Transact-SQL)