Lesson 4: View #temp tables during debugging

In this lesson, you will learn how to use Sybase WorkSpace to view and change the contents of the referenced tables for an Adaptive Server Enterprise server database.

�Before you can perform the steps in this lesson, create a stored procedure and then run the stored procedure, as described in the previous lessons, “Lesson 2: Create a stored procedure” and “Lesson 3: Run a stored procedure”.

StepsViewing #temp tables during debugging

  1. If necessary, select Window|Open Perspective|Database Development from the main menu bar to open the Database Development perspective.

  2. In the Database Explorer view, open the Procedures & Functions folder under the appropriate pubs sample database.

  3. Find the play_proc stored procedure that you created in “Lesson 2: Create a stored procedure” and double-click it to open it in the SQL Editor.

    To view the contents of a #temp table for a stored procedure, use the stored procedure debugger. When you stop at a breakpoint in the stored procedure, you can view and modify the contents of the #temp table.

    First, add breakpoints to the stored procedure and then invoke the debugger.

  4. Add breakpoints to the following lines.

    If you look at the following figure, these statements correspond to line numbers 10, 14, 16, 18, and 22. However, if you added comments or selected the Recompile option when creating the stored procedure, your line numbers may differ.

    Create table #play_table
    
    select @V1 = @P1, @V2 = @P2
    
    select @V1, @V2
    
    insert #play_table values (@V1, @V2)
    
    select #play_table.c1, #play_table.c2 from #play_table
    

    You can add a breakpoint using either method:

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

    Now you will debug the stored procedure.

  5. Right-click in the SQL Editor and select Debug from the context menu.

    The Configure Parameters wizard displays.

  6. Next, retain or change the values for the stored procedure invocation.

    As you can see, the Value fields display the values you selected when initially running the stored procedure.

    NoteEnter values the first time you run/debug a stored procedure. When subsequently running the stored procedure, you can use the values you previously entered or enter new values.

  7. Click OK to run the procedure.

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

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

    Sybase WorkSpace stops at the first breakpoint on line 10.

  9. Click the Resume icon once, located on the Debug view toolbar, to step to the next breakpoint.

    The Referenced Tables view opens in the upper right corner of the Database Debug perspective.

  10. Click the #play_table temp table in the Referenced Tables view to display its contents.

    At this point the temp table is empty because you just created it.

  11. Finish walking through the breakpoints until you reach line 22 (just below the insert statement) by clicking the Resume icon three more times.

    Now, you can view and modify the contents of the #play_table.

  12. View the contents of the #play_table by clicking #play_table in the left pane of the Referenced Tables view.

  13. Modify the contents of #play_table; right-click anywhere in the right pane of the Referenced Tables view and select Edit Table Data from the context menu.

    The #play_table editor displays, which enables you to insert, delete, and modify rows in the table.

  14. Change the value 123 to 456.

    Select 123 in the C2[int] column, right-click, and select Update Value from the context menu.

    Sybase WorkSpace highlights the existing value.

  15. Enter 456 to overwrite the existing value.

  16. Insert another row in the table using either method:

    Add some new values for the new row.

  17. Right-click anywhere in the #play_table grid and select Commit to Database from the context menu.

    The #play_table contents you just changed in the table editor now match the table contents in the Referenced Tables view.

  18. Continue execution of the stored procedure and confirm that the changes you made to the #play_table display in the SQL Results view.

    Display the play_proc editor by clicking its tab. Complete the stored procedure execution by selecting the Resume icon one more time.

  19. Click the Result1 tab in the SQL Results view to see the values reflect the modifications that you made during the debug session.

  20. Select File|Close on the main menu bar to close the editor.

You can easily make changes to the stored procedure and save it back to the server.��