Home All Groups Group Topic Archive Search About

Triggers and bach insert

Author
19 May 2006 6:12 PM
bill
I'm using an INSERT INTO...SELECT * FROM bulk statement to insert records
into a table. If I write a trigger on the target table that executes on
INSERT, will the trigger fire for each row inserted? If not, how can I get
the trigger to fire for each row?

Thanks in advance

Author
19 May 2006 6:14 PM
SQL Menace
>>will the trigger fire for each row inserted?
No, triggers fire per statement

use the inserted and deleted pseudo-tables to do what you need to do


Denis the SQL Menace
http://sqlservercode.blogspot.com/
Author
19 May 2006 6:24 PM
Adam Machanic
First of all, please note that INSERT INTO from a SELECT is not a "bulk"
operation ("bulk" has a special meaning, so it's important to
differentiate).  Triggers in SQL Server fire once per operation -- in this
case, once for the INSERT itself.  Within the scope of a trigger you can
access the "inserted" and "deleted" virtual tables, which will allow you to
programatically act on the rows that were affected by the operation.  The
"inserted" table contains all of the rows that were inserted -- so you
should be able to do whatever it is you need to do by acting on that table.


--
Adam Machanic
Pro SQL Server 2005, available now
http://www.apress.com/book/bookDisplay.html?bID=457
--


Show quote
"bill" <b***@no.com> wrote in message
news:OSeP382eGHA.3792@TK2MSFTNGP03.phx.gbl...
> I'm using an INSERT INTO...SELECT * FROM bulk statement to insert records
> into a table. If I write a trigger on the target table that executes on
> INSERT, will the trigger fire for each row inserted? If not, how can I get
> the trigger to fire for each row?
>
> Thanks in advance
>
>

AddThis Social Bookmark Button