Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 506391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:41:47+00:00 2026-05-13T06:41:47+00:00

Every change of data in some row in database should save the previous row

  • 0

Every change of data in some row in database should save the previous row data in some kind of history so user can rollback to previous row data state. Is there any good practice for that approach? Tried with DataContract and serializing and deserializing data objects but it becomes little messy with complex objects.

So to be more clear:

  1. I am using NHibernate for data access and want to stay out off database dependency (For testing using SQL server 2005)

  2. What is my intention is to provide data history so every time user can rollback to some previous versions.

An example of usage would be the following:

  • I have a news article
  • Somebody make some changes to that article
  • Main editor see that this news has some typos
  • It decides to rollback to previous valid version (until the newest version is corrected)

I hope I gave you valid info.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:41:47+00:00Added an answer on May 13, 2026 at 6:41 am

    Tables that store changes when the main table changes are called audit tables. You can do this multiple ways:

    • In the database using triggers: I would recommend this approach because then there is no way that data can change without a record being made. You have to account for 3 types of changes when you do this: Add, Delete, Update. Therefore you need trigger functionality that will work on all three.

    Also remember that a transaction can modify multiple records at the same time, so you should work with the full set of modified records, not just the last record (as most people belatedly realize they did).

    Control will not be returned to the calling program until the trigger execution is completed. So you should keep the code as light and as fast as possible.

    • In the middle layer using code: This approach will let you save changes to a different database and possibly take some load off the database. However, a SQL programmer running an UPDATE statement will completely bypass your middle layer and you will not have an audit trail.

    Structure of the Audit Table

    You will have the following columns:
    Autonumber PK, TimeStamp, ActionType + All columns from your original table
    and I have done this in the following ways in the past:

    Table Structure:
    Autonumber PK, TimeStamp, ActionType, TableName, OriginalTableStructureColumns

    This structure will mean that you create one audit table per data table saved. The data save and reconstruction is fairly easy to do. I would recommend this approach.
    Name Value Pair:
    Autonumber PK, TimeStamp, ActionType, TableName, PKColumns, ColumnName, OldValue, NewValue

    This structure will let you save any table, but you will have to create name value pairs for each column in your trigger. This is very generic, but expensive. You will also need to write some views to recreate the actual rows by unpivoting the data. This gets to be tedious and is not generally the method followed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table where each row has some data and the user can
I have a number input that should trigger jQuery on every change. To do
I need that on every page change or on some elemetents (a, input[button, submit],
I need to load some data into a view every time it is shown.
I have a web page that displays dynamic data which changes every 2 seconds.
I would like to have a field which is updated on every change(insertion, modification),
I have a jQuery event handler that reacts to every change in an: <input
Every time I change a .coffee file in the development mode, Rails creates a
I have a value of Android accelerometer x axis, and on every 0.18 change
In my activity there is a toggle button. I want every time you change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.