Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Trigger defined for Insert, Update Expand / Collapse
Author
Message
Posted Wednesday, December 19, 2007 1:35 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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?
Post #434953
Posted Wednesday, December 19, 2007 3:04 PM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Monday, April 14, 2014 1:52 PM
Points: 1,478, Visits: 1,020
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.
Post #435014
Posted Wednesday, September 12, 2012 9:54 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 2:15 PM
Points: 1,135, Visits: 1,150
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
Post #1358322
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse