Saving Versions of Data

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Number1SuperGuy
Forum Newbie
Posts: 10
Joined: Thu Jun 17, 2010 11:21 am

Saving Versions of Data

Post by Number1SuperGuy »

Hi everyone, new web developer here working on a big project, in need of a bit of advice.

To make this very simple, I'm making a database for utility meter readings for a group of apartment complexes. I'm mostly not having any issues, but they want a way to be able to roll back the data in case any mistakes are made. I figured it wouldn't be too hard to automatically record the current version of the data every time someone clicks "save", but I can't think of an elegant way to do it. Will I have to create a new table for the data every time someone clicks "save" or is there a better way to do it?

Please ask if you need any clarification. Thanks for helping!

- Matt
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: Saving Versions of Data

Post by JakeJ »

Real simple.

In your table where you're recording the transactions have the following fields

id - (auto number field)
resident_id - obviously from your table of residents.
date - date field
reading - The meter reading for that period.

This way you can track historic data by querying all the entries from a particular resident and do it in date order. And a mistake is easy enough to fix, you just query the date and update the number.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Saving Versions of Data

Post by josh »

Instead of editing the rows, you add a column to track the "revision" #. Then instead of editing a row you just insert a new row with a higher revision number.
kamak malik
Forum Newbie
Posts: 1
Joined: Sun Jul 11, 2010 8:12 am

Re: Saving Versions of Data

Post by kamak malik »

it just about saving data.........oh yes i like it
Post Reply