|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, December 19, 2007 3:47 PM
Points: 1,
Visits: 4
|
|
Is there an "easy/quick" way to determine inside the trigger itself whether it is being fired because of an Insert or because of an Update when a trigger has been defined for Insert, Update? Without inquiring whether a row exists or not, is there a system variable that can determine this?
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 8:25 AM
Points: 1,467,
Visits: 922
|
|
If your trigger is For Update, Insert
there is not any system information identifying what action caused the trigger to fire.
You could duplicate your code, and create 1 trigger for insert, and 1 trigger for update, or test for Existing rows as you mentioned.
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Today @ 12:57 PM
Points: 740,
Visits: 790
|
|
You could do something like:
DECLARE @operation as Varchar(10); DECLARE @Count as int; SET @operation = 'Inserted';
SELECT @Count = COUNT(*) FROM DELETED; if @Count > 0 BEGIN SET @operation = 'Deleted'; SELECT @Count = COUNT(*) FROM INSERTED; IF @Count > 0 SET @operation = 'Updated' END
HTH, Rob
|
|
|
|