Sdílet prostřednictvím


Transact-SQL Debugger Fundamentals

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.

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.

    When you start the debugger, it pauses on the first line of code in the Query Editor window. To run to the first breakpoint that you have set, you can use the Continue feature. You can also use the Continue feature to run to the next breakpoint from any location at which the window is currently paused.

  • 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 are 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. SQL Server Management Studio opens a new Database Engine Query Editor window that is populated with the source code for the module, places the window into debug mode, and then pauses execution 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 Stepping 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.

For more information about how to view information, see Viewing Transact-SQL Debugger Information.

See Also

Other Resources