Hey All,
We have a table named "document" with following fields:
documentnum, documenttypenum, description, filename, uploadedon, createdby
We would like to add versioning capability to the document records. New functionality would involve a) creating a new document b) replacing a document with a newer version c) deleting the latest version and making the older version current d) ...
Quote:
Originally Posted by joehansen
What would be the best way to structure the database table(s) so that the queries for the above operations would not just be simple but also run fast?
Couldn't you just have a timestamp in the record and then the current document is the one with the latest timestamp. If you ...
Thanks for the reply, Mike!
I am torn between having one single document table with a timestamp field or having two tables, document table along with the documentarchive table.
Wouldn't you think the SQL SELECT queries would be simpler and would perform better if I had two tables?
Thank you,
Joe
Hi…
IMO, using two tables gives no benefit. You shall have to move records back and forth from one table to the other one. Of course, any simple query on "DocumentTable" will run faster than Mike's query, because the subselect on each row. But if your query grabs only a few rows, you'll never see the difference.
In your place, I would use Mike's design. If your queries aren't fast enough then...
Wikipedia has a decent article on temporal database design. Usually you would add a ValidStart and ValidEnd datetime columns to reflect when the row was current. The current record has a ValidEnd datetime of some specific date in the distant future so it is easy to find.
If you are going to have a huge number of document revisions (more than 20 per document) then I would go with an archive ...
Normally I would recommend an archive table, but in your case records are not being "permanently archived", and can be change back to an active state. So, the single table may be your best option. Note though, that a single table with start and stop columns will not enable you to determine the history of when a document was in use (if it had multiple start and stop times), while an archive ...
OK,
I would have a Document table, With Effective and Termination Dates (null), with a version Number for the document that is incremented by 1 any time the document was modified (via a trigger)
I would also move all data images to a history table (via a trigger) when anything on the row was modified
MOO
Thank you, Brett Kaiser, blindman, MarkATrombley and Laurent for your kind replies. You all have been consistent in saying that a single table would serve my purpose best. So here's the key document table columns that I am looking at right now:
documentkey (unique)
documentnum
activefrom
activeuntil
version (optional)
latest (default true; optional)
Thanks for all your help ...
Quote:
So here's the key document table columns that I am looking at right now:
documentkey (unique)
documentnum
activefrom
activeuntil
version (optional)
latest (default true; optional)
Few questions : Surely the latest field is unnecessary as you'd just look for either look for records where the current date is between the from ...
Something is yet unclear to me in the desired behavior: what you want is:
-- a stack, i.e. returning to version n-2 will throw away n and n-1.
-- an history, i.e. returning to version n-2 deletes nothing but "duplicates" n-2 to n+1
Mike's design (and my contribution) apply to a stack. Mark's is more about an history. And your final design seems to me a mix of the two !
If an history is ...
Thank you, Brett Kaiser, blindman, MarkATrombley and Laurent for your kind replies. You all have been consistent in saying that a single table would serve my purpose best. So here's the key document table columns that I am looking at right now: documentkey (unique) documentnum activefrom activeuntil version (optional) latest (default true; optional) Thanks for all your help guys, Joe
Quote: So here's the key document table columns that I am looking at right now: documentkey (unique) documentnum activefrom activeuntil version (optional) latest (default true; optional) Few questions : Surely the latest field is unnecessary as you'd just look for either look for records where the current date is between the from and until dates. If the field defaults to true does this mean you might have more than one record with...
Something is yet unclear to me in the desired behavior: what you want is: -- a stack, i.e. returning to version n-2 will throw away n and n-1. -- an history, i.e. returning to version n-2 deletes nothing but "duplicates" n-2 to n+1 Mike's design (and my contribution) apply to a stack. Mark's is more about an history. And your final design seems to me a mix of the two ! If an history is wanted, I would use two...
Wikipedia has a decent article on temporal database design. Usually you would add a ValidStart and ValidEnd datetime columns to reflect when the row was current. The current record has a ValidEnd datetime of some specific date in the distant future so it is easy to find. If you are going to have a huge number of document revisions (more than 20 per document) then I would go with an archive table, otherwise keeping it in one table is best.
Normally I would recommend an archive table, but in your case records are not being "permanently archived", and can be change back to an active state. So, the single table may be your best option. Note though, that a single table with start and stop columns will not enable you to determine the history of when a document was in use (if it had multiple start and stop times), while an archive table would.
OK, I would have a Document table, With Effective and Termination Dates (null), with a version Number for the document that is incremented by 1 any time the document was modified (via a trigger) I would also move all data images to a history table (via a trigger) when anything on the row was modified MOO
Related threads on "dBforums - Database Support Community":
Thread profile page for "Document Table Record Versioning" on http://www.dbforums.com.
This report page is a snippet summary view from a single thread "Document Table Record Versioning", located on the Message Board at http://www.dbforums.com.
This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity