Using the Transact-SQL Debugger
The Transact-SQL debugger in SQL Server Management Studio enables you to find errors in Transact-SQL scripts, stored procedures, triggers, and functions by observing their run-time behavior. You can start the debugger when you are using the Database Engine Query Editor window. By using the Transact-SQL debugger, you can do the following:
Step through the Transact-SQL statements in the editor line by line, or set breakpoints to stop at specific lines.
Step into or over Transact-SQL stored procedures, functions, or triggers that are run by the code in the editor window.
Watch the values that are assigned to variables, and observe system objects such as the call stack and threads.