Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging stored procedures in SQL Server Management Studio

Is there a way to step into the stored procedure code in SQL Server Management Studio? I know this is possible with Visual Studio, but I am looking for a dependable debugging solution from within Management Studio

like image 271
Nick Avatar asked Jan 06 '10 22:01

Nick


People also ask

How do I debug SQL stored procedure in SQL Server Management Studio 19?

To debugging SP, go to database->Programmability->Stored Procedures-> right click the procedure you want to debug->select Debug Procedure.

Can you debug stored procedure in SQL Server?

The Transact-SQL debugger allows you to interactively debug stored procedures by displaying the SQL call stack, local variables, and parameters for the SQL stored procedure.


2 Answers

Only with SQL 2008 and SSMS 2008. Select from menu 'Debug\Start Debugging' or press Alt+F5 and will launch the step by step T-SQL debugger.

On 2005 the only way is to attach Profiler and monitor for the SP:StmtCompleted event, which is not exactly debugger step-by-step, but at least you'll see the execution flow. Not to be done on a production machine, obviously.

like image 144
Remus Rusanu Avatar answered Oct 14 '22 23:10

Remus Rusanu


I have written a pretty detailed blog post about it here:

http://www.diaryofaninja.com/blog/2010/11/23/debugging-sql-queries-function-amp-stored-procedures-with-sql-management-studio

Basically the gist of it is that you enter your sql query to execute your stored procedure, and instead of pressing F5 or hitting the exclamation, you hit the play button and use F10 and F11 to step through and step into your stored procs.

This is very handy but no one seems to use it.

like image 44
Doug Avatar answered Oct 14 '22 23:10

Doug