What operation type invoked a trigger in SQL Server 2008?

Posted by Neil Moss on Stack Overflow See other posts from Stack Overflow or by Neil Moss
Published on 2010-06-18T08:41:34Z Indexed on 2010/06/18 8:43 UTC
Read the original article Hit count: 375

Filed under:
|
|

I'm contemplating a single SQL trigger to handle INSERT, UPDATE and DELETE operations as part of an auditing process.

Is there any statement, function or @@ variable I can interrogate to find out which operation type launched the trigger?

I've seen the following pattern:

declare @type char(1)
if exists (select * from inserted)
    if exists (select * from deleted)
        select @Type = 'U'
    else
        select @Type = 'I'
else
    select @Type = 'D'

but is there anything else a little more direct or explicit?

Thanks,
Neil.

© Stack Overflow or respective owner

Related posts about tsql

Related posts about sql-server-2008