Note that there are some explanatory texts on larger screens.

plurals
  1. POMaintaining audit log for entities split across multiple tables
    primarykey
    data
    text
    <p>We have an entity split across 5 different tables. Records in 3 of those tables are mandatory. Records in the other two tables are optional (based on sub-type of entity).</p> <p>One of the tables is designated the entity master. Records in the other four tables are keyed by the unique id from master.</p> <p>After update/delete trigger is present on each table and a change of a record saves off history (from deleted table inside trigger) into a related history table. Each history table contains related entity fields + a timestamp.</p> <p>So, live records are always in the live tables and history/changes are in history tables. Historical records can be ordered based on the timestamp column. Obviously, timestamp columns are not related across history tables.</p> <p>Now, for the more difficult part.</p> <ol> <li>Records are initially inserted in a single transaction. Either 3 or 5 records will be written in a single transaction.</li> <li>Individual updates can happen to any or all of the 5 tables.</li> <li>All records are updated as part of a single transaction. Again, either 3 or 5 records will be updated in a single transaction.</li> <li>Number 2 can be repeated multiple times.</li> <li>Number 3 can be repeated multiple times.</li> </ol> <p>The application is supposed to display a list of point in time history entries based on records written as single transactions only (points 1,3 and 5 only)</p> <p>I'm currently having problems with an algorithm that will retrieve historical records based on timestamp data alone.</p> <p>Adding a HISTORYMASTER table to hold the extra information about transactions seems to partially address the problem. A new record is added into HISTORYMASTER before every transaction. New HISTORYMASTER.ID is saved into each entity table during a transaction. Point in time history can be retrieved by selecting the first record for a particular HISTORYMASTER.ID (ordered by timestamp)</p> <p>Is there any more optimal way to manage audit tables based on AFTER (UPDATE, DELETE) TRIGGERs for entities spanning multiple tables?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload