Hi Friends,

DBCC INPUTBUFFER() is the TSQL command that we generally use to find out the submitted statement to the SQL Server Instance. Sometimes I use this command to troubleshoot the blocking scenario. If I know the session id of blocking and blocked session, then I can easily find out the TSQL statement/command passing that session id to DBCC INPUTBUFFER().

There is some limitation of this DBCC command. If I want to know the last TSQL statement for two/more sessions, then I have to execute this DBCC command with session ids, same number of times. In simple words you can say that we cannot join the output of this DBCC command with other system views or dynamic management views or functions.

In SQL Server 2016, Microsoft has provided the new dynamic management function to overcome the above issue i.e. “sys.dm_exec_input_buffer”. This dmf required two parameters – session id and request id. Let me show you the same – I am going to execute below command in a new query window. For me the session id is 57 as shown below.

SQL Server 2016 – sys.dm_exec_input_buffer

Now, I’ll try to use the dmf to get the details of last tsql statement:

SQL Server 2016 – sys.dm_exec_input_buffer 2

Now, we can also join the output this dmf with other dmv/dmf. Lets say, if I want to know the last TSQL statement for all the sessions, then I can get that information easily.

SQL Server 2016 – sys.dm_exec_input_buffer 3



Prince Kumar Rastogi

Like us on FaceBook | Join the fastest growing SQL Server group on FaceBook

Follow Prince Rastogi on Twitter | Follow Prince Rastogi on FaceBook