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 2000 Forums
 SQL Server Development (2000)
 How Can i know who Fired the Triggers

Author  Topic 

CLages
Posting Yak Master

116 Posts

Posted - 2004-08-21 : 23:25:31
I have this Triggers, works Fine, but i would like to Put a Extra Column (D = Deleted , U= Updated) in the Log.dbo.area
But to do this i need to know if the trigger was fired by update or Delete.

i would not like to make two Triggers one for UPDATE and other for DELETE

tks Carlos Lages





CREATE TRIGGER LogArea ON [dbo].[Area]
FOR UPDATE ,DELETE

AS
Insert Log.dbo.area
Select Getdate(), System_User , d.* from Deleted as D


maydo
Starting Member

20 Posts

Posted - 2004-08-22 : 03:39:03
After Update the affected records exist in both deleted and inserted tables.
After Delete only the deleted table has the afected records.
You'll need the PK though.
Are You sure you want to reinsert those records in the same Table ?!


Insert Log.dbo.area

Select Getdate(), System_User , 'U', d.* from Deleted as D inner join inserted as I on I.PK = D.PK

UNION ALL

Select Getdate(), System_User , 'D', d.* from Deleted as D left join inserted as I on I.PK = D.PK where I.PK is NULL

Go to Top of Page

CLages
Posting Yak Master

116 Posts

Posted - 2004-08-23 : 09:29:46
Tks.
I did not know that After an Update I get both deleted and inserted tables.

tks again
Carlos Lages
Go to Top of Page
   

- Advertisement -