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 2008 Forums
 Transact-SQL (2008)
 While use SqlBulkCopy trigger not triggered

Author  Topic 

ThomasSE
Starting Member

1 Post

Posted - 2011-09-26 : 18:15:06
I have created a trigger for a particular table.While i insert a record the trigger is working perfectly but while i use SqlBulkCopy to upload records from excel to database the trigger is not working what should i do.



this is my trigger



ALTER TRIGGER [dbo].[CreateDummyforOthers] ON [dbo].[StudentPersonal]
AFTER INSERT
AS
DECLARE @StudentID as bigint
SET @StudentID=( SELECT @@IDENTITY)
INSERT INTO dbo.StudentAcademic (StudentID) Values(@StudentID)
INSERT INTO dbo.StudentOldAcademic (StudentID) Values(@StudentID)

Thanks.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-09-26 : 18:58:52
You'll need to verify if SqlBulkCopy has an option to fire the trigger. It sounds like it is off by default for it just like normal BULK INSERT: http://msdn.microsoft.com/en-us/library/ms187640.aspx

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

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-09-26 : 18:59:44
Oh your trigger isn't going to work for bulk inserts anyway though as it isn't coded to handle batches of rows. Your trigger is only coded to handle one row. See this for more info: 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/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -