When I do this (Update Employee Set Basic = Basic+30) the Update statement executes, but the trigger only fires the last row, not all updated rows. Can you help me with a trigger for each row that is the same as Oracle?

    Requires Free Membership to View

Triggers in SQL Server do not actually fire only for the last row affected; Rather, they fire once for the entire set of affected rows. Within the scope of a trigger you have access to two virtual tables, "inserted" and "deleted." The inserted table contains all of the inserted rows, for an insert trigger, and the updated versions of all of the affected rows for an update trigger.

The deleted table contains all of the deleted rows, for a delete trigger, and the previous versions of all of the affected rows for an update trigger. By working with these virtual tables you can write any logic necessary against any of the individual rows that were affected in the operation.

This was first published in June 2006

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.