Bewerken

Share via


Transact-SQL debugger

Applies to: SQL Server

The Transact-SQL debugger helps you find errors in Transact-SQL code by investigating the run-time behavior of the code. After you set the Database Engine Query Editor window to debug mode, you can pause execution on specific lines of code and inspect information and data that is used by or returned by those Transact-SQL statements.

T-SQL debugging is available in SQL Server Data Tools for Visual Studio.

Stepping through Transact-SQL Code

The Transact-SQL debugger provides the following options that you can use to navigate through Transact-SQL code when the Database Engine Query Editor window is in debug mode:

  • Set breakpoints on individual Transact-SQL statements.

    A breakpoint specifies a point at which you want execution to pause so you can examine data. When you start the debugger, it pauses on the first line of code in the Query Editor window. To run to the first breakpoint, use Continue. You can also use Continue to run to the next breakpoint from any location at which the window is currently paused. You can edit breakpoints to specify actions such as the conditions under which the breakpoint should pause execution, information to print to the Output window, and change the location of the breakpoint.

  • Step into the next statement.

    This option enables you to navigate through a set of statements one by one, and to observe their behavior as you go.

  • Step either into or over a call to a stored procedure or function.

    If you're sure there are no errors in a stored procedure, you can step over it. The procedure is executed in full, and the results are returned to the code.

    If you want to debug a stored procedure or function, you can step into the module. A new Database Engine Query Editor window opens that populates with the source code for the module. The window is in debug mode, and execution pauses on the first statement in the module. You can then navigate through the module code, for example, by setting breakpoints or stepping through the code.

For more information about how the debugger enables you to navigate code, see Step Through Transact-SQL Code.

Viewing debugger information

Each time the debugger pauses execution on a specific Transact-SQL statement, you can use the following debugger windows to view the current execution state:

  • Locals and Watch. These windows display currently allocated Transact-SQL expressions. Expressions are Transact-SQL clauses that evaluate to a single, scalar expression. The Transact-SQL debugger supports viewing expressions that reference Transact-SQL variables, parameters, or the built-in functions that have names that start with @@. These windows also display the data values that are currently assigned to the expressions.

  • QuickWatch. This window displays the value of a Transact-SQL expression, and enables saving that expression to a Watch window.

  • Breakpoints. This window displays the currently set breakpoints and enables you to manage them.

  • Call Stack. This window displays the current execution location. And also provides information about how execution passed from the original Query Editor window through any functions, stored procedures, or triggers to reach the current execution location.

  • Output. This window displays various messages and program data, such as system messages from the debugger.

  • Results and Messages. These tabs on the Query Editor window display the results of previously executed Transact-SQL statements.

Transact-SQL debugger tasks

Task Description Article
Describes how to configure the Transact-SQL debugger for remote debugging. Configure firewall rules before running the Transact-SQL debugger
Describes how to start, stop, and control the operation of the debugger. Run the Transact-SQL Debugger
Describes how to use the Transact-SQL debugger to step through code. Step Through Transact-SQL Code
Describes how to use the Transact-SQL debugger to step through stored procedure code. Debug Stored Procedures
Describes how to use the debugger to view Transact-SQL data, such as parameters and variables, and system information. Transact-SQL Debugger Information