Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 22nd, 2011, 07:36 PM
shamit8 shamit8 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2011
Posts: 1 shamit8 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 6 sec
Reputation Power: 0
Updates in audit table

Hi,

I have to create a audit/history table on a master table so that I can store the old/current state of data in my audit table. I am planning to write following program --
1. Created the audit table with similar number of records.
2. Everyday at a particular time I will compare the audit/main table and push the records in audit table which are either updated or not present in the audit table so that the audit table = main table + old state of data.

I am unable to figure out the proper way to implement the point 2 above in oracle database.

Can someone please share his experience/ thoughts on the above problem.

Thanks a lot in advance.

Cheers!!
Amits

Reply With Quote
  #2  
Old May 23rd, 2011, 01:17 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
I think you need an
after insert or update or delete trigger on the main table.

I suggest that the audit table has its own incrementing surrogate PK field plus a timestamp field to indicate the moment of insertion for sorting.

You will have to decide how to indicate deletion.
Insertion will simply be the earliest record containing the main table PK.

Last edited by clivew : May 23rd, 2011 at 01:19 PM. Reason: Added comments about insertion and deletion

Reply With Quote
  #3  
Old May 23rd, 2011, 02:04 PM
shammat shammat is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Oct 2003
Location: Germany
Posts: 2,685 shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 3 Days 19 h 57 m 33 sec
Reputation Power: 284
You don't need to code anything. Use a flashback archive on your main table and you'll be able to query the contents of your table at any point in the past.

Code:
SELECT *
FROM your_table
AS OF TIMESTAMP '2011-05-19 17:04:12'

Reply With Quote
  #4  
Old May 23rd, 2011, 07:29 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
Shammat:

A couple of questions as I have not used this feature.
1. Is it actually available before version 11?
2. I see how it gives you a flashback snapshot of a table at various selected TIMESTAMPS
but how do you query for a history of changes to a record?
e.g. With an audit table I might want to track changes something like:

SQL Code:
Original - SQL Code
  1. SELECT * FROM AUDIT_TABLE
  2. WHERE MAIN_PK_COL = :MAIN_PK_COL
  3. ORDER BY TIMESTAMP_COL


Of course actual change history queries might be more complex.

Clive

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Updates in audit table

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap