Best Relational DataBase Representation Of Time Bound Hierarchies

后端 未结 4 1535
温柔的废话
温柔的废话 2021-02-02 04:27

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

4条回答
  •  灰色年华
    2021-02-02 04:59

    A couple of flat tables can work here. For each row, we need columns ID, Name, ParentID, and InactivatedDatetime (which defaults to null). Set the datetime for the old Doc belonging to Joe indicating that that record is no longer valid and move it off to an archive table (for cleanliness), and then create a new row (a near copy of the original row) for a new Doc with Moe's ID as the ParentID. The drawback with this approach is that the person being moved must get a new ID, which may not be convenient.

提交回复
热议问题