Lesson 3: Debug the trigger

In this lesson, you will debug your trigger. Before you can do so, you must create the insert_title trigger and run it.

  1. If necessary, click to open the insert_title trigger in the SQL Editor.

  2. Add breakpoints to lines 19, 21, and 22 using either method:

    In case your line numbers differ, add breakpoints to the following lines.

    if (select count(*) from inserted)>0
    

    rollback transaction
    

    raiserror 99999 "We are not allowed to insert anything into the titles table."
    

    Sybase WorkSpace indicates a breakpoint by a light blue dot next to the line number in the SQL Editor.

  3. To debug the trigger; right-click anywhere in the SQL Editor and select Debug from the context menu.

    The Modify attributes and launch dialog box displays.

    Sybase WorkSpace displays the values you previously entered in “Running and debugging a trigger”.

  4. Click Debug to continue.

    Execution starts and the Confirm Perspective Switch dialog box displays, which confirms that you want to change to the Database Debug perspective.

  5. Select Yes in the Confirm Perspective Switch box to switch to the Database Debug perspective.

    Sybase WorkSpace stops at the first breakpoint on line 19.

    The expanded select from inserted statement executes, and the trigger returns the contents of the inserted special table. You can see the contents of the inserted table in the Result0 tab in the SQL Results view.

  6. Click the Resume icon, located on the Debug view toolbar, only once to go the next breakpoint.

    The if statement evaluates to true and the trigger enters the begin-end block.

  7. Click the Resume icon two more times to step through the remainder of the trigger.

    The initiating INSERT statement fails as expected because the trigger was designed to print an error message during any attempt to insert data in this table (raiserror command).

  8. Select File|Close on the main menu bar to close the trigger.

You now know how to view an existing trigger, create a new trigger, and run and debug a trigger. You also learned how to query the contents of the inserted special table to view its contents during debugging.