Problem solve Get help with specific problems with your technologies, process and projects.

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.

Dig Deeper on Microsoft SQL Server Database Development

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.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.