How should I setup a table in a database to keep the history of records? -
i'm trying setup sql server database asp.net mvc site both store latest information history of changes data.
the information site comes xml files uploaded user. site parses through xml , writes contained information sites database. elements in successive uploads may represent same thing, data may have changed. yet said before want keep track of every version.
the table bellow shows 1 way thinking of approaching this. create duplicate records each item in each upload. new items match in previous uploads assigned same id, each item assigned unique upload id.
upload 1: erik , sara added upload 2: erik renamed eric, bill added upload 3: sarah grew 2" taller, eric removed. [persons table] personid name height uploadid 1 erik 71 1 1 eric 71 2 2 sarah 70 1 2 sarah 70 2 2 sarah 72 3 3 bill 76 2 3 bill 76 3 [uploads table] uploadid uploadtime 1 3/09/2011 2 4/01/2011 3 4/11/2011 however, doesn't seem optimal solution me because of how information ends being duplicated in database. there better way approach changes saved each upload?
i think problem is persons table no longer contains information persons. contains information on updloads. i'm going recommend won't decrease size of database; make little easier understand , work with.
persons personid, name, height 1 eric 71 2 sarah 72 3 bill 76 upload uploadid, uploadtime 1 3/09/2011 2 4/01/2011 3 4/11/2011 persons_edit personid, uploadid, changesql, changedescription 1 1 "insert persons(name, height) values('erik', 71)" "erik added" 1 2 "update persons set name='eric' name='erik'" "changed erik's name" .... ... ...... .... i don't think can beyond make tables simpler or database smaller. can see, persons_edit table going largest table. database you're using might provide mechanisms automatically (some sort of transaction recording or something) i've never used i'll leave other people on stackoverflow make suggestions if exist. if persons_edit table gets large, can @ deleting entries on week/month/year old. decision on when you.
some other reasons making change, in first table, had use personid , uploadid primary key persons table. so, recent version of person within application, have had select person id, , order uploadid , select 1 largest upload id every time transaction on 1 person.
another benefit don't have bunch of fancy sql edit history. select * persons_edit table.
Comments
Post a Comment