SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Auditing Insert Update and Delete Operations


Auditing Insert Update and Delete Operations

Author
Message
suresh kartheek malladi
suresh kartheek malladi
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 85
I would like to put in place a process into the current oltp databases to facilitate the retrieval of 1) new records inserted; 2) updated records; 3) deleted records (if any).

I have an idea of using triggers to insert into an “audit” table the new, updated, deleted records with the appropriate timestamps on each. There is a caveat to this approach: I am not 100% certain what the previous developers used for retrieving identity. If they have not used the proper method ( i.e. @@Identity ), this can prove problematic to data integrity (e.g. wrong id’s used in a fk reference) especially if the audit tables have their own auto identity.

I would like to know is there any other solution apart from using triggers to implement this so analyze the and propose a strategy to implement a solution.
Jack Corbett
  Jack Corbett
SSC-Forever
SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)

Group: General Forum Members
Points: 41939 Visits: 14925
I have always used audit tables and triggers for this type of auditing. Yes, you could cause a problem if the application code is using @@Identity to return the latest identity value if you put an identity column in your audit table. If you don't know what was used I would suggest not using an identity value on the audit table. My audit table would add these columns to the columns in that source table:

audit_action char(1) -- values would be I, U, D for insert, update, delete
audit_date smalldatetime

Then your unique/primary key would be source_id, audit_date, audit_action. Odds are the only joining you would do on the table will be on the source id you'd use that index for any join operations. You could cluster on audit_date, but I would think that a heap would be okay in this instance.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search