In my opinion, if the code for insert, update, and delete is significantly different (no common elements), then it makes the most sense to separate in to different triggers. But, if you want to know whether a trigger is happening based on insert, update, or delete, you can play around with this...
In the code I show below, I create a new table, and then create a trigger on that table. This allows you to play with the various execution paths to see what's going on. Once you are satisfied that this is working properly, implement the same logic in your real trigger (and then drop the test table).
Code:
Create Table TestTrigger(Id Int)
Code:
Create TRIGGER TestTrigger_Trigger
ON testTrigger
For INSERT,DELETE,UPDATE
AS
BEGIN
SET NOCOUNT ON;
Declare @Insert Bit
Declare @Delete Bit
If Exists(Select * From Inserted)
Set @Insert = 1
Else
Set @Insert = 0
If Exists(Select * From Deleted)
Set @Delete = 1
Else
Set @Delete = 0
If @Insert = 1 and @Delete = 1
Begin
Select 'Update'
End
Else If @Insert = 1
Begin
Select 'Insert'
End
Else If @Delete = 1
Begin
Select 'Delete'
End
Else
Begin
Select 'No Change'
End
END
Once you have the table and the trigger, play around with some queries to see what happens.
Ex:
[tt][blue]
Insert Into TestTrigger Values(1)
Update TestTrigger Set Id = 7 Where Id = 8
Update TestTrigger Set Id = 7
Delete From TestTrigger Where ID = 20
Delete From TestTrigger
[/blue][/tt]
Run each query separately and see what the output of the trigger shows. You should see all four combinations (Insert, Update, Delete, No Change).
Now... you're probably worried a little bit about performance, right? Well... I can tell you that the Exist checks at the beginning of this code is VERY fast. In fact, all it really needs to do is check to see if there is any data in the inserted or deleted tables. So, even if millions of rows are affected, this code will be very fast. Of course, I make no claims regarding the code you add later.
Make sense?
-George
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom