• Skip to main content
  • Skip to primary sidebar

DBA Diaries

Thoughts and experiences of a DBA working with SQL Server and MySQL

Using DBCC INPUTBUFFER for SQL Server troubleshooting

May 27, 2012 by Andy Hayes Leave a Comment

dba toolboxIn my last post on sp_who2 I demonstrated how this handy utility can help you in your SQL Server troubleshooting efforts.

Continuing on from this, I am going to cover DBCC INPUTBUFFER

What is DBCC INPUTBUFFER ?

It is a command used to identify the last statement executed by a particular SPID. You would typically use this after running sp_who2. The great thing about this DBCC command is that it shows the last statement executed, whether running or finished.

How to use

DBCC INPUT BUFFER will generate errors so ensure that the space between INPUT and BUFFER is omitted.

In this example, I have just run run sp_who2 and identified that my lead blocker is SPID number 54 so I would run as follows:

T-SQL:

[sourcecode language=’sql’]DBCC INPUTBUFFER(54)[/sourcecode]
Here is a simple demonstration. In a new query window run this
[sourcecode language=’sql’]BEGIN
UPDATE Orders SET Amount = 500 WHERE OrderID = 1;[/sourcecode]
Now in a second query window run this
[sourcecode language=’sql’]UPDATE Orders SET Amount = 200 WHERE OrderID = 1;[/sourcecode]
Now run sp_who2 to identify the lead blocker followed by DBCC INPUTBUFFER using the lead blocker SPID. Here are my results with the column “EventInfo” providing the detail that I need on the T-SQL which is causing the problem. It is possible to copy and paste the code into a query window for analysis.

using dbcc inputbuffer for sql server troublshooting

Permissions needed for DBCC INPUTBUFFER

You need to be a sysadmin or have the VIEW SERVER STATE permission to be able to run this command.

Conclusion

Again, like sp_who2, this handy command should be in your “DBA Toolbox”.

UJNZMQQN5JCV

Related Posts:

  • How to fix "conversion failed when converting date and/or time from character string"
    How to fix "conversion failed when converting date…
  • sql grouping sets
    Using SQL GROUPING SETS for Multiple GROUP BY…

Filed Under: All Articles, SQL Server Administration Tagged With: dbcc, sql server, troubleshooting

About Andy Hayes

Andy Hayes is a DBA working with SQL Server since version 7.0. He has a wonderful wife and two beautiful children. He loves database technology, playing cricket, and blogging. He is passionate about sharing his experiences as a DBA and learning more to further his understanding and knowledge. You can follow me on Twitter, check out my Facebook page or follow me on Google+

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Categories

  • All Articles (84)
  • Career Development (8)
  • MySQL Administration (18)
  • MySQL Performance (2)
  • SQL Server Administration (24)
  • SQL Server News (3)
  • SQL Server Performance (14)
  • SQL Server Security (3)
  • SQL Tips and Tricks (21)

Top 10 Popular Posts

  • Using sp_change_users_login to fix SQL Server orphaned users
  • MySQL SHOW USERS? – How to List All MySQL Users and Privileges
  • How to shrink tempdb
  • How to Transfer Logins to Another SQL Server or Instance
  • How to Delete Millions of Rows using T-SQL with Reduced Impact
  • T-SQL – How to Select Top N Rows for Each Group Using ROW_NUMBER()
  • New T-SQL features in SQL Server 2012 – OFFSET and FETCH
  • How to Kill All MySQL Processes For a Specific User
  • Using exec sp_who2 to help with SQL Server troubleshooting
  • How to fix “conversion failed when converting date and/or time from character string”

Recent Posts

  • How to fix “conversion failed when converting date and/or time from character string”
  • Using SQL GROUPING SETS for Multiple GROUP BY Queries in a Single Query
  • How to Setup MySQL Master Master Replication
  • How To Use SQL to Convert a STRING to an INT
  • How to set up MySQL Replication Tutorial

Search

Connect

  • Twitter
  • Facebook
  • RSS

About

  • Cookie Policy
  • Disclaimer
  • About
Copyright ©