On bulk insert, Insert trigger only works for the first record and does not work for all the other records but trigger works properly when records are inserted using cursor.
Insert trigger updates few columns of destination table. To insert bulk data I am using following script
INSERT INTO DestinationTable (Column1, Column2)
SELECT * FROM SourceTable
I get few columns in trigger of inserted record like the following script, and work on them to update columns of DestinationTable
SELECT @col1 = Column1, @col2 = Column2, FROM INSERTED
- Why on bulk insert, trigger does not
work? - Am I missing something or I have to
use cursor?
I am using SQLServer 2005
EDIT
Trigger Code
http://stashbox.org/957108/InsertTrigger.sql
Thanks.
From the code you posted it looks like by bulk insert you just mean inserting multiple rows. Not this BULK INSERT?
The
INSERTEDpseudo table contains all the rows inserted by the statement. It is not a row level trigger. You would need to use a cursor for RBAR processing or, ideally, process it as a set. For example if you are Updating another table you could join onto theinsertedtable and update all the rows in one statement.