Trigger mode

When inside a trigger is there any way to determine what mode the trigger is using (insert, update, or delete)?

I know that if you have access to the inserted table it must be either an insert or an update.

Likewise, if you have access to the deleted table it must be either a delete or an update.

But is there a method to determine exactly what operation the trigger is performing?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Yes, have a look at my web-site I demonstrate some code to do this, and give the template. --> Look under Links -> Articles, Trigger examples.
The Trigger Code gives examples of both single/multi row updates within the trigger for firing off various dependancys as rqd.
danblake - can't find an article called "Trigger examples".

sifuhall - you answered your own question. This (or similar) is the only way:

DECLARE @inserts int, @deletes int, @mode char(6)

SELECT @inserts = count(*) from inserted
SELECT @deletes = count(*) from deleted

IF @inserts > 0 AND @deletes > 0
   SET @mode = 'UPDATE'
IF @inserts > 0 AND @deletes = 0
   SET @mode = 'INSERT'
IF @inserts = 0 AND @deletes > 0
   SET @mode = 'DELETE'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The exact title is Article: DDL_Trigger_Migration_Updates

this gives the example within Appendix B, as follows:
if (exists (select top 1 *  from inserted ) and
exists (select top 1 *  from deleted )  )
            GOTO UPD /*Goto the update section of the trigger*/
if exists (select top 1 *  from inserted )  
            GOTO INS /*Goto the insert section of the trigger*/
if exists (select top 1 *  from deleted )  
            GOTO DEL /*Goto the delete section of the trigger*/

/*Delete section of trigger*/
/*Insert section of trigger*/
/*Update section of trigger*/
Yes - we have basically the same solution packaged up in a different way.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.