Lesson 2: View the inserted special table within a trigger

During the debugging process, one way to ensure that data modifications are consistent throughout all tables in a database is called referential integrity. To manage referential integrity, you can create triggers that take effect when you give insert, update, and delete commands for particular tables or columns.

You can view the contents of the inserted and deleted special tables, which contain data that the trigger inserts, deletes, or updates (delete followed by insert). These special tables are temporary and exist only in memory during trigger execution. Once the trigger stops running, these tables no longer exist. After debugging, you would want to remove or comment out these Select * from statements.

In this lesson, you will learn how to view and change contents of the sample titles table, and how to query the contents of the inserted special trigger table so that you can view its contents in the SQL Results view.

NoteBefore you can perform this tutorial, you must create the insert_title trigger and run it, as described above.

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

  2. Find the insert_title trigger that you created in “Lesson 2: Create a new trigger”.

    In the Database Explorer view, expand the Tables folder under the appropriate pubs sample database. Next, expand the titles folder and then the Triggers folder.

  3. Double-click the insert_title trigger to open it in the SQL Editor.

    Next, add select statements to the trigger that return the contents of the inserted rows in the SQL Results view.

  4. Add the following SQL statement to the trigger after the BEGIN command but before the comments (line 11).

    select * from inserted
    

    Format your code in the SQL Editor to look like this.

  5. Right-click anywhere in the SQL Editor window and select Save to Server to save the changes.

    The server expands the * (asterisks) contained in the select statement.

    Next, add breakpoints to prepare for debugging the trigger.