|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Using Triggers to create an audit record
I'm trying to use a trigger to generate an audit record in a new table (basically duplicate the source table). The problem that I am experiencing is trying to get a single record to be created in the target anytime the source is updated (new field entered or one updated) and I don't want 2 records to be created i.e. one for an updated field and another for an inserted field (unless these are 2 seperate operations ofcourse). The below trigger creates 2 records in hte target:
CREATE TRIGGER Tr_CAN_MARKET_DATA_AUDIT ON [dbo].[CAN_MARKET_DATA] FOR UPDATE AS INSERT INTO CAN_MARKET_DATA_AUDIT (MRKT_DATA_SEQ, RPRTD_SRC_TXT, CRG_VOL) SELECT MRKT_DATA_SEQ, RPRTD_SRC_TXT, CRG_VOL FROM deleted INSERT INTO CAN_MARKET_DATA_AUDIT (MRKT_DATA_SEQ, RPRTD_SRC_TXT, CRG_VOL) SELECT MRKT_DATA_SEQ, RPRTD_SRC_TXT, CRG_VOL FROM inserted Any ideas on how to get a single instance of an updated record (inserted field or update) to generate a single audit record ? |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft SQL Server > Using Triggers to create an audit record |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|