Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 24th, 2003, 09:30 AM
dvamartin dvamartin is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: UK
Posts: 0 dvamartin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to dvamartin
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 ?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Using Triggers to create an audit record


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT