Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Triggers when bulk inserting

Author  Topic 

surreal
Starting Member

4 Posts

Posted - 2008-05-21 : 13:04:29
Hi,

hope this is the right forum for this...

I'm using asp.net and the SqlBulkCopy command to insert a few lines of data into a table. I have the SqlBulkCopyOption.FireTriggers set, and a simple trigger on the table to take the inserted data and update a couple of other tables. Works fine if I only insert one record, but as soon as there are multiple records it fails.

So I presume that the trigger isn't firing on every line, but only once when the bulk insert is done?

Am I missing a trick? I can post some code if it will help - I'll have to get a screengrab of the error too.

cheers

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2008-05-21 : 13:11:55
Trigger always fire only once per insert, regardless of how many records are affected. Your trigger code needs to be able to handle multi-record transactions.
Look up the use of the virtual "Inserted" and "Deleted" tables in Books Online.

e4 d5 xd5 Nf6
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-21 : 13:15:14
http://weblogs.sqlteam.com/tarad/archive/2004/09/14/2077.aspx

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page
   

- Advertisement -