You can manage the Transact-SQL Debugger using the Debug menu commands, the Debug toolbar, operation panes, and keyboard shortcuts.
You can control which statements are run with the Debugger. One of the most common debugging tasks is stepping through code, which means executing one line at a time.
The Debug menu provides the following commands for stepping through code:
If the next statement invokes a Transact-SQL stored procedure, function, or trigger, the Debugger opens a new SQL Editor document that is already in the debug mode. You can move through that procedure, function, or trigger code, for example, by setting breakpoints or stepping through the code.
On a nested function call, Step Into steps into the most deeply nested function. If you use Step Into on a call like Func1(Func2()), the Debugger steps into the function Func2().
If the statement invokes a stored procedure, function, or trigger, Step Over executes that and then halts at the first line outside the function. Use Step Over if you are sure there are no errors in the procedure, function, or trigger code and you want to avoid stepping into it.
Use Step Out when you are inside a function call and want to return to the calling function. Step Out resumes execution of your code until the function returns, then breaks at the return point in the calling function.
The Debugger breaks execution of the code when execution reaches a breakpoint. Use Continue, Step Into, Step Over, Step Out from the Debug menu to continue the execution.
Stop debugging terminates the debugging session. It should not be confused with breaking execution, which temporarily halts execution of the process you are debugging but leaves the debugging session active.
Note
The Stop Debugging command does not always immediately terminate the program. If the process is in break mode, it stops execution immediately. Otherwise, the program continues finalizing in the background, allowing you to start a new debugging session.
Only two program instances can be finalized in the background at the same time. A new debugging session can begin only after at least one of those background processes has completed.
To stop a debugging session, select Stop Debugging on the Debug menu.
Note
If a module is compiled for debugging, execution pauses at the last line of code. This allows you to inspect the state of program variables in the Watches pane.
If the module is not compiled for debugging, execution does not pause at the last line, and the Debugger exits without breaking.
To stop the current run and immediately begin a new one, use the Restart command. This ends the active debugging session and starts a new session from the beginning.
Breakpoints inform the Debugger to pause execution on a specific Transact-SQL statement. When the Debugger reaches a statement with a breakpoint, it pauses execution, allowing you to view debugging information, such as variable values and parameters.