Ask the Expert

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

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

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: