I have 2 tables, Table-A and Table-A-History.
Table-Acontains current data rows.Table-A-Historycontains historical data
I would like to have the most current row of my data in Table-A, and Table-A-History containing historical rows.
I can think of 2 ways to accomplish this:
-
whenever a new data row is available, move the current row from
Table-AtoTable-A-Historyand update theTable-Arow with the latest data (viainsert into selectorselect into table)or
-
whenever a new data row is available, update
Table-A‘s row and insert a new row intoTable-A-History.
In regards to performance is method 1 or 2 better? Is there a better different way to accomplish this?
Logging changes is something I’ve generally done using triggers on a base table to record changes in a log table. The log table has additional columns to record the database user, action and date/time.
Logging triggers should always be set to fire last. Otherwise, a subsequent trigger may rollback the original transaction, but the log table will have already been updated. This is a confusing state of affairs.