Below is the code i'm using to determine if the operation in an insert/update/delete. This question is two part.
One - this is a correct way of determining the operation type. Two - Is this the best way of determining the operation type.
BEGIN
DECLARE @ActionType CHAR (1)
IF NOT EXISTS (SELECT * FROM deleted) AND EXISTS (SELECT * FROM inserted)
BEGIN
SET @ActionType = 'I'
END
IF EXISTS (SELECT * FROM deleted) AND EXISTS (SELECT * FROM inserted)
BEGIN
SET @ActionType = 'U'
END
IF EXISTS (SELECT * FROM deleted) AND NOT EXISTS (SELECT * FROM inserted)
BEGIN
SET @ActionType = 'D'
END
Select @ActionType;
End
INSERT, one forDELETE, and a third forUPDATE- then it's clear from the beginning what kind of operation you're dealing with .... - marc_s