How to debug T-SQL statement in SQL Server Management Studio
Debugging is an important feature for every programming language with no exception SQL Server has this to help developer trace the their code and remove potential logical issue in the code before moving to production environment or simply to find the bug in the code.
SQL Server management Studio (SSMS) provide easy way to debug T-SQL statements.
Expectation: This blog post is to show how to use debug feature in SSMS with simple T-SQL statement.
declare @i as int, @n as int;
set @i = 0;
set @n = 5;
while @i < @n
set @i = @i + 1;
Step 1: Open new query window and paste the above code
Step 2: Click Debug button on the toolbar
Step 3: Once debug starts, another debug related toolbar and windows (local variables, call stack) will show up. We can view and modify local variables and parameters, view global variables, as well as control and manage breakpoints while debugging.
Step 3: Click Step into (F11 – function key) to execute step by step.
This image is captured after 3 iterations. so, we can see the value of the variable @i = 3 and @n =5.
Try other debugging features in SSMS and keep your code robust. Thanks.