SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software SQL Server and T-SQL Development Tutorials
Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Windows, Windows Phone, SAP and ABAP, like SAP UI5, Screen Personas, etc.




download SQL Server 2016
download SQL Server 2014



How to Debug Stored Procedure in SQL Server 2008

Create a simple SQL stored procedure in SQL Server 2008 database.
Just to make a short introduction for how to debug stored procedure in SQL Server 2008, I code the below t-sql code and execute it to create stored procedure in sample SQL Server database.

CREATE Procedure spDebugStoredProcedure
(
 @i int
)
AS

While @i < 10
begin
 If @i = 3
  print 'Three'
 Else
  print @i

 set @i = @i + 1
end




Then you can open a new Query Editor windows using Ctrl+N in SQL Server Management Studio.
Paste the following t-sql command which calls the sql stored procedure we have just created in SQL Server 2008 database.

EXEC spDebugStoredProcedure 1

If you press F5, or Execute button the SQL engine will execute the sql stored procedure code with given input parameter values and display the output.
But in order to debug stored procedure in SQL Server 2008, t-sql developers can use Debug menu within the SSMS screen.
Pressing F11 or F10 will activate the SQL Server Management Studio Debugging screens and processes.
In order to step into stored procedure t-sql codes, the sql developer can continue with F11 Step Into short-cut.
If you step into SQL stored procedure codes, a new query editor will be opened displaying the t-sql source scripts of the related stored procedure.

By clicking on the grey area on the left of the debugging screen, t-sql programmers can place breakpoint on the sql code lines they want.

debug-stored-procedure-in-sql-server-2008

Within the SQL Server 2008 SSMS, many debugging windows will be activated for more control and information to sql developers.
Locals, Watch 1, Call Stack, Breakpoints, Command Window, and Output sub-screens are those helper debugging screens while debugging stored procedure in SQL Server 2008.

sql-server-2008-debugging-windows-to-debug-stored-procedure






Related SQL Resources

SQL Server Articles

SQL Server 2012

SQL Server Tools

SQL Blog

MS SQL Server Forums









Copyright © 2004 - 2017 Eralper YILMAZ. All rights reserved.
Community Server by Telligent Systems