Q

Updating triggers in SQL Server

By working with virtual tables in SQL Server triggers, you can manipulate executions for any rows in a table that were affected in the operation.

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?
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

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchBusinessAnalytics

SearchDataCenter

SearchDataManagement

SearchAWS

SearchOracle

SearchContentManagement

SearchWindowsServer

Close