Debugging a Trigger

To debug a Microsoft SQL Server trigger:

  1. In Database Explorer, choose your test database.

  2. Expand the Triggers folder, and then double click the trigger to open it.
  3. Change the current view from Main to SQL.

    While opening a trigger the Main view is set as default. You are not able to insert a breakpoint in this view.

  4. Set a breakpoint for the trigger. Left-click in the gray margin next to the SET statement to set a breakpoint in the trigger. This step is obligatory: if you do not set a breakpoint in the trigger, you will skip over its code when you try to step into it.
  5. Expand the Procedures folder, and then double-click the procedure to open it.
  6. Set a breakpoint for the stored procedure that will fire the trigger. Left-click in the gray margin next to the statement.
  7. Click Start Debugging, and enter input parameters for the procedure.
  8. Step through the code using the F11 key or the Step Into button, or press CTRL+F5 to move directly to the breakpoint. At the statement, when you press F11 again, you will step into the trigger.
  9. Step through the trigger until you exit back to the stored procedure, and continue to the end.

Call Stack Window

There are two database objects in the Call Stack window: the trigger and the procedure. You may notice the yellow arrow next to the trigger which identifies the stack frame where the execution pointer is currently located.

You can get back to the procedure source code by double-clicking the procedure in the Call Stack window.

A green arrow indicates that you have stepped back to the parent code that has called the trigger.