What in everyone\'s opinion is the best representation for a time-bound hierarchy in SQL?
What I mean by this is:
- On any given date you have a normal tree hierarch
I can think of a couple of reasonable solutions, depending on how your data is being used and how it changes.
1) Assuming today's hierarchy is the most important. I'd store today's hierarchy with a conventional ParentId column in each record. For previous versions of the hierarchy I'd have a history table of
ItemId, ParentId, ValidFromDate, ValidToDate
Any time the hierarchy changes, you add a new row to the history table.
2) If any/all of the hierarchies are of equal importance, I'd store a base line hierarchy and then implement a hierarchy transaction table.
TransactionId, ItemId, Action (Move/Delete/Add), DateTime, OldParentId, NewParentId