1

I have some table where each entry can have different time validity. entry looks like this: (Id, ValidFrom, ValidTo). There can be more such entries with the same Id but with a different validity. (Validity should not overlap). I need to do insert/delete/update operations at current time or any future time point.

All this could be handled in business logic of the application, but I would like to refer to this table from other tables using foreign key.

I found out that Temporal Tables could be the way, but there is a small problem. The SysStartTime and SysEndTime columns are determined automatically by the time of INSERT/UPDATE and cannot be set when inserting/updating.

Is there a way how to store a validity information for each entry in database table while allowing foreign key constrains? Is that demand even reasonable?

4

1 回答 1

0

临时表可以为您提供解决方案,前提是您的 FK 的主表也是临时表。至于validFrom和validTo的手动管理,可以(例如使用触发器)但容易出错。只是要解决一些问题:
1. 有效期不应重叠(已经提到)。
2. 有效期不应有间隔。

另请注意,历史数据需要巨大的存储量。

于 2016-05-08T16:06:16.920 回答