liveBook · Manning

Execute With Debugger

As explained in 100 SQL Server Mistakes and How to Avoid Them

Execute With Debugger is a query-execution command that starts T-SQL execution under interactive debugging control.

Execute With Debugger starts T-SQL execution under interactive control, pausing at the first statement so you can inspect and advance through procedure logic. section 7.3

Mistake: trusting the error line

Running dbo.CalculateCampaignSummary produces a divide-by-zero error. Start it with Execute With Debugger, choose Step Into, and inspect variables in Locals. The zero value of @AvgCPM reveals the immediate cause; an Immediate-window query then shows that 42 rows were assigned where one was expected. section 7.3

Use the debugger to:

  • Run diagnostic queries without pausing execution in the Immediate window. section 7.3

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Explains pausing, stepping, variable inspection, and diagnostic queries, then stops short of broader debugging features.
Examples
Demonstrates debugging CalculateCampaignSummary and tracing incorrect variable assignments caused by 42 returned rows.
What it assumes
Assumes familiarity with T-SQL stored procedures, query windows, and executing procedures with parameters.
What you can do after
Diagnose/debug with SQL Server tools by stepping through procedures, inspecting variables, and testing queries during execution.
How it connects
Connects stored procedures with breakpoints, the Locals window, the Immediate window, and divide-by-zero errors.

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.