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

  • Home
  • SEARCH
  • 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 537707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:57:19+00:00 2026-05-13T09:57:19+00:00

Every time I need to design a new database I spend quite some time

  • 0

Every time I need to design a new database I spend quite some time
thinking on how I should set up the database schema to keep an audit log of
the changes.

Some questions have already been asked here about this, but I don’t agree that
there is a single best approach for all scenarios:

  • Database Design For Revisions
  • Best design for a change log auditing database table
  • Ideas on database design for capturing audit trails

I have also stumbled upon this interesting article on Maintaining a Log of Database Changes that tries to list the pro and cons of each approach. It’s very well written and has interesting information, but it has made my decisions even harder.

My question is: Is there a reference that I can use, maybe a book or something like a decision tree that I can refer to decide which way should I go based on some
input variables, like:

  • The maturity of the database schema
  • How the logs will be queried
  • The probability that it will be need to recreate records
  • What’s more important: write or read performance
  • Nature of the values that are being logged (string, numbers, blobs)
  • Storage space available

The approaches that I know are:

1. Add columns for created and modified date and user

Table example:

  • id
  • value_1
  • value_2
  • value_3
  • created_date
  • modified_date
  • created_by
  • modified_by

Major cons: We lose the history of the modifications. Can’t rollback after commit.

2. Insert only tables

Table example:

  • id
  • value_1
  • value_2
  • value_3
  • from
  • to
  • deleted (Boolean)
  • user

Major cons: How to keep foreign keys up to date? Huge space needed

3. Create a Separate history table for each table

History table example:

  • id
  • value_1
  • value_2
  • value_3
  • value_4
  • user
  • deleted (Boolean)
  • timestamp

Major cons: Needs to duplicate all audited tables. If the schema changes it will be needed to the migrate all the logs too.

4. Create a Consolidated history Table for All Tables

History table example:

  • table_name
  • field
  • user
  • new_value
  • deleted (Boolean)
  • timestamp

Major cons: Will I be able to recreate the records (rollback) if needed easily? The new_value column needs to be a huge string so it can support all different column types.

  • 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-13T09:57:19+00:00Added an answer on May 13, 2026 at 9:57 am

    One method that is used by a few wiki platforms is to separate the identifying data and the content you’re auditing. It adds complexity, but you end up with an audit trail of complete records, not just listings of fields that were edited that you then have to mash up to give the user an idea of what the old record looked like.

    So for example, if you had a table called Opportunities to track sales deals, you would actually create two separate tables:

    Opportunities
    Opportunities_Content (or something like that)

    The Opportunities table would have information you’d use to uniquely identify the record and would house the primary key you’d reference for your foreign key relationships. The Opportunities_Content table would hold all the fields your users can change and for which you’d like to keep an audit trail. Each record in the Content table would include its own PK and the modified-by and modified-date data. The Opportunities table would include a reference to the current version as well as information on when the main record was originally created and by whom.

    Here’s a simple example:

    CREATE TABLE dbo.Page(  
        ID int PRIMARY KEY,  
        Name nvarchar(200) NOT NULL,  
        CreatedByName nvarchar(100) NOT NULL, 
        CurrentRevision int NOT NULL, 
        CreatedDateTime datetime NOT NULL
    

    And the contents:

    CREATE TABLE dbo.PageContent(
        PageID int NOT NULL,
        Revision int NOT NULL,
        Title nvarchar(200) NOT NULL,
        User nvarchar(100) NOT NULL,
        LastModified datetime NOT NULL,
        Comment nvarchar(300) NULL,
        Content nvarchar(max) NOT NULL,
        Description nvarchar(200) NULL
    

    I would probably make the PK of the contents table a multi-column key from PageID and Revision provided Revision was an identity type. You would use the Revision column as the FK. You then pull the consolidated record by JOINing like this:

    SELECT * FROM Page
    JOIN PageContent ON CurrentRevision = Revision AND ID = PageID
    

    There might be some errors up there…this is off the top of my head. It should give you an idea of an alternative pattern, though.

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

Sidebar

Related Questions

Every time I need to work with date and/or timstamps in Java I always
Every time I need to do something N times inside an algorithm using C#
I don't edit CSS very often, and almost every time I need to go
Every time I create a new project I copy the last project's ant file
Every time I turn on my company-owned development machine, I have to kill 10+
Every time I create an object that has a collection property I go back
Every time I have to estimate time for a project (or review someone else's
Every time a user posts something containing < or > in a page in
Every time I try to run a small application that uses a Derby DB
Every time I call this method my NSMutableData is leaking and I cannot figure

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.