tracing value changes in my tables

Reply

Join Date: Nov 2008
Posts: 19
Reputation: Sally123 is an unknown quantity at this point 
Solved Threads: 0
Sally123 Sally123 is offline Offline
Newbie Poster

tracing value changes in my tables

 
0
  #1
Dec 9th, 2008
hi

I am learning mysql and have created a table for auditing purposes with fields below , but my problems is I dont know how to go about inserting data into it whenever an event ocurs on my primary tables.especially getting the oldvalue,newvalue,column and table name fields after updates are done on my table

I need a purely simple trigger script that can update this table whenever my primary table gets updated by the users.

these are the only fields that I need for auditing purposes.

HR_Audit_Module table
AuditID(PK)
Table_Name,
tblRow_Id ----this is the ID from the table that gets updated to identify the column name,
Updated_By,
Update_when,
Old_Value,
New_Value,
FieldName (column name),
Operation_Type -- this should be --(update,insert or delete)

thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: tracing value changes in my tables

 
0
  #2
Dec 10th, 2008
If it is purely simple, you may as well write it on your own and ask us specific questions where you get stuck. We are not going to write the script for you.
PS : You should write it on your own even if it is not purely simple
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 19
Reputation: Sally123 is an unknown quantity at this point 
Solved Threads: 0
Sally123 Sally123 is offline Offline
Newbie Poster

Re: tracing value changes in my tables

 
0
  #3
Dec 10th, 2008
Originally Posted by verruckt24 View Post
If it is purely simple, you may as well write it on your own and ask us specific questions where you get stuck. We are not going to write the script for you.
PS : You should write it on your own even if it is not purely simple
-------------------------
here is something that I have tried or have in my mind on how things should work but I am failing. the thing is I dont want to monitor specific field but all the fields in my table as per the audit table above .



  1. CREATE trigger mytest
  2. after UPDATE,DELETE
  3. on mytest
  4. AS
  5.  
  6. DECLARE @field_name VARCHAR(50), @OldValue VARCHAR(50), @NewValue VARCHAR(50)
  7.  
  8. if UPDATE
  9. BEGIN
  10.  
  11. SELECT @field_name = column_Name
  12.  
  13. SELECT @OldValue = columnname() FROM deleted
  14.  
  15. SELECT @newValue = columnname() FROM updated
  16.  
  17. INSERT INTO Audit(Old_Value,NewValue ,Update_by,Updated_When,tblName,field_Name)
  18. SELECT @OldValue,@NewValue,user(),CURRENT_DATE(),'mytest',@fieldName FROM mytest;
Last edited by peter_budo; Dec 12th, 2008 at 7:02 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the MySQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC