I have got table person which have got 2 triggers (if data is inserted, triggers make update) all triggers are after insert later I insert information about events to other table and I get (Update, Update, Insert) but should be this (Insert, Update, Update) do you know why?
I have got problem with this example:
DECLARE @HistoryType CHAR(1) --"I"=insert, "U"=update, "D"=delete
SET @HistoryType=NULL
IF EXISTS (SELECT *
FROM inserted)
BEGIN
IF EXISTS (SELECT *
FROM deleted)
BEGIN
--UPDATE
SET @HistoryType='U'
END
ELSE
BEGIN
--INSERT
SET @HistoryType='I'
END
END
ELSE IF EXISTS(SELECT *
FROM deleted)
BEGIN
--DELETE
SET @HistoryType='D'
END
IF @HistoryType='U' or @HistoryType='I'
//do something
END
Example from this post:
How to copy an inserted,updated,deleted row in a SQL Server trigger(s)