Updating triggers in SQL Server
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

    By submitting your registration information to SearchSQLServer.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSQLServer.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

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