Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help needed for identifying DML Trigger event type

Author  Topic 

sneh sharma
Starting Member

4 Posts

Posted - 2008-06-19 : 05:51:55
Hi,

I have a query regarding DML Triggers.

I have created a trigger ON a table AFTER Insert, Update staement. In the trigger's body I am making a call to a stored procedure. In the procedure, I want to know the Trigger invoked due to which event : insert or Update as I have to handle bith the cases differently.
But I am not able to find out any SQL server function or property which can distinguish between INSERT and Update events of a trigger.

Waiting for the needful.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-19 : 05:57:12
you can distinguish Insert update actions with the help of internal tables INSERTED & DELETED

IF EXISTS(SELECT 1 FROM INSERTED) AND EXISTS(SELECT 1 FROM DELETED)
for update

and

IF EXISTS(SELECT 1 FROM INSERTED) AND NOT EXISTS(SELECT 1 FROM DELETED)

for insert
Go to Top of Page

sneh sharma
Starting Member

4 Posts

Posted - 2008-06-19 : 06:24:07
No, I want to know that the last event that occured on table was an insert or update, not that any insert or update ever occured on table.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-19 : 06:40:53
1) Read the log
2) Provide some auditing



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

sneh sharma
Starting Member

4 Posts

Posted - 2008-06-19 : 06:52:02
It worked....
thanks visakh
Go to Top of Page
   

- Advertisement -