Link to home
Start Free TrialLog in
Avatar of David Glover
David GloverFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Why does my trigger fire on Update but not on Insert?

Can you guys suggest why my trigger only works for mass update but not for mass insert?
CREATE TRIGGER [dbo].[ExampleTrigger] 
   ON  [dbo].[ExampleTable] 
   AFTER INSERT, UPDATE
AS 
BEGIN
	SET NOCOUNT ON;
	UPDATE ExampleTable SET ExampleTable.ExampleField= 1
	FROM ExampleTable S INNER JOIN Inserted I 
        ON S.ExampleID = I.ExampleID
END

Open in new window

I realise the code is a bit redundant by virtue of setting 1 to ExampleField... in my real world scenario this is a function derived value.
Reagrds,
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

No, the trigger looks OK to me, for either INSERTs or UPDATEs.
Avatar of David Glover

ASKER

Hi Scott,
I've examined this more closely and indeed it does work when I insert a record.
Something I didn't mention was that prior to this single record insert test I was bulk inserting data using SSIS integration using identity insert... I am presuming something about this doesn't cause triggers to fire?
Regards,
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Problem was definitely linked to the SSIS, couldn't see a don't fire triggers flag to set mind, I have worked around it anyhow.
Thanks Scott!