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 6560935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:31:30+00:00 2026-05-25T13:31:30+00:00

I have a database that it is always changing… updates, inserts and deletes. For

  • 0

I have a database that it is always changing… updates, inserts and deletes.
For statistics reason, we need sometime to “go back in time” (-: and query the database like we are in the past.

For example:
I have a table named user, I have updated yesterday one of the users like the following:

update user set status = 1 where user_id = 2656

The old status was 0, so if i can “go back in time” to yesterday and query it ill get status 0, and if ill query it now, ill get status 1.
I know that one way to do it is to trigger update,insert and delete and log it to different tables, but it is not so clean, and will make the development complicated.

I hope you got me right, not so simple to explain for none English speaker…

Edit-1
We have few algorithms in the application and we fix them and upgrade them always, we have to know how the database was in the past so we can work on the algorithms, we have queries/interface that can be changed to support that (I am aware that this is not a one week project, we have the resources for that)

Thanks

  • 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-25T13:31:31+00:00Added an answer on May 25, 2026 at 1:31 pm

    Option 1 Enable the binary log.
    This will safe all updates, inserts and deletes.
    There are query tools for the binlog.

    See:
    http://dev.mysql.com/doc/refman/5.0/en/binary-log.html
    http://www.mydigitallife.info/how-to-read-mysql-binary-log-files-binlog-with-mysqlbinlog/

    Option 2 Create a trigger that saves the changes
    The trigger save a data into a parallell database that has the same layout as the original database, except all tables have two extra fields. A unqiue id called log_id and a timestamp. Whenever a field changes you have the trigger log in in the log.
    You need at least an after_update and after_delete trigger and I would recommend a after_insert trigger as well. If you feel like it, you can add a third field to every tables called operation, which is an ENUM('insert','delete','update').

    DELIMITER $$
    
    CREATE TRIGGER au_table1_each AFTER UPDATE ON table1 FOR EACH ROW
    BEGIN
      insert into back_to_the_past.table1_log (`timestamp`,operation,f1,f2,f3.f4) 
        values (now(), 'update', OLD.f1, OLD.f2, OLD.f3, OLD.f4);
    END $$
    
    DELIMITER ;
    

    Of course if you create an extra timestamp type field in table1_log you don’t need to get it explicitly to now() the DB will do that.

    See: http://dev.mysql.com/doc/refman/5.0/en/triggers.html

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

Sidebar

Related Questions

Currently our new database design is changing rapidly and I don't always have time
I have a database that contains a date and we are using the MaskedEditExtender
I have a database that I would like class files generated from, and also
I have a database that many different client applications (a smattering of web services,
I have a database that contains a table that looks a bit like this:
I have a database that i'm dealing with which is updated every few hours
I have a database that is stuck in single-user mode. I kill the process
We have a database that persist our metadata and data. Our metadata is produced
I have a database that hold's a user's optional profile. In the profile I
I have a database that I used specifically for logging actions of users. The

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.