How to debug a Microsoft SQL Server trigger

This topic demonstrates how to debug a Transact‑SQL trigger by setting breakpoints, stepping through code, and inspecting variable values.

Prerequisite

Use the sample scripts to create the dbo.trg_ScheduleDetail_Insert trigger in the TestScheduleDB database.

Debug a trigger

1. In Database Explorer, right-click the required database and select New SQL to open a SQL document.

2. Type the following SQL statement:

INSERT INTO dbo.ScheduleDetail (ScheduleId, DateOut, TimeSheetDate, AbsenceCode) VALUES (11, '2025-07-01', '2025-07-01', NULL);

3. To start debugging, on the Debug toolbar, click Step Into Step Into or press F11 until a SQL document with the CREATE statement for the trigger opens.

Alternatively, in the top menu, select Debug > Step Into.

Start debugging a trigger

Note

The yellow arrow identifies the stack frame where the execution pointer is currently located.

4. Optional: To view the variable value, hover over it in the query.

The quick info tip will be displayed.

View the value of the variable

Note

Ensure the Enable code completion feature is selected in Tools > Options > Text Editor > Code Completion > General.

5. To insert a breakpoint, do one of the following:

  • Right-click the line of the code where you want to set a breakpoint and select Insert Breakpoint.
  • Place the cursor on the line of the code you want to break on, navigate to the top menu, then select Debug > Toggle Breakpoint, or press F9.
  • Click on the gray bar to the left of the code where you want to insert a breakpoint.

In the SQL Editor, the line with the breakpoint will be highlighted in red.

Insert breakpoints

6. On the Debug toolbar, click Continue, or press Alt+F5.

The Breakpoints pane opens where you can view and manage breakpoints.

7. To add the variable to the Watches pane, right-click the variable, then select Add Watch.

Add watch to the variable

8. On the Debug toolbar, click Debug the procedure, or press Alt+F5.

Alternatively, click Step Into or press F11 repeatedly to step through the trigger.

9. To stop debugging, do one of the following:

  • In the top menu, select Debug > Stop Debugging or press Shift+F5.

  • On the Debugger toolbar, click Stop Debugging.