Skip to content
Advertisement

Trigger: How does the inserted table work? How to access its rows?

I have the following table

I created the following trigger:

And inserted the following values

It shows this:

enter image description here

But I was expecting something like this:

  • After the 1st insertion, the trigger is executed -> one row is shown in the inserted table.
  • After the 2nd insertion, the trigger is executed -> two rows are shown in the inserted table.
  • After the 3rd insertion, the trigger is executed -> three rows are shown in the inserted table.

According to msdn.microsoft all the rows inserted are in this table.


How can I access the inserted table so that I can see all the expected rows and not separately?

Advertisement

Answer

You can not. From the Use the inserted and deleted Tables article on microsoft.com, you can read:

The inserted table stores copies of the affected rows during INSERT and UPDATE statements.

That means that the inserted table will only contain rows for the current INSERT or UPDATE statement.

If you do want to see all rows for several such INSERT or UPDATE statements, you will have to store these rows in a table you created yourself.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement