Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Versioning data in SQL Server so user can take a certain cut of the data

I have a requirement that in a SQL Server backed website which is essentially a large CRUD application, the user should be able to 'go back in time' and be able to export the data as it was at a given point in time.

My question is what is the best strategy for this problem? Is there a systematic approach I can take and apply it across all tables?

like image 701
Mark Robinson Avatar asked Mar 07 '11 14:03

Mark Robinson


2 Answers

Depending on what exactly you need, this can be relatively easy or hell.

Easy: Make a history table for every table, copy data there pre update or post insert/update (i.e. new stuff is there too). Never delete from the original table, make logical deletes.

Hard: There is an fdb version counting up on every change, every data item is correlated to start and end. This requires very fancy primary key mangling.

like image 186
TomTom Avatar answered Oct 03 '22 02:10

TomTom


Just add a little comment to previous answers. If you need to go back for all users you can use snapshots.

like image 43
ceth Avatar answered Oct 03 '22 01:10

ceth