1

Everywhere I am reading, when a merge statement happens, it will fire the triggers (INSERT, UPDATE, DELETE) in no particular order. I have a basic merge:

MERGE dbo.Users WITH(HOLDLOCK) as tgt
USING #Users as src
ON tgt.ID = src.ID
WHEN NOT MATCHED BY INSERT
(..)
VALUES(..)
OUTPUT INSERTED.ID, src.UserID into #Results;

However, I have an insert trigger on Users but nothing ever gets run from the trigger perspective. Follow-up update statements do get run and I see the results of those trigger executions, just not the inserts from the merge.

Is there anything I can do about that? I'm surprised it's not working when it's documented that others do get that functionality to work...

  • 1
    Hi, could you add a reproducable example? When testing with my own merge statement + trigger it does work. Using DB<>Fiddle can help in supplying an example that clarifies your question. – Randi Vertongen Jun 7 at 21:50
  • Is the trigger smart enough to handle multiple rows being inserted? Does it work if you limit the merge to insert a single row? – Sir Swears-a-lot Jun 8 at 1:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.