SQL 服务器临时 table 仅用于历史更改

SQL Server temporal table for historical changes only

我有一个 table 经常更改的数据。我不关心 30 天以内的数据更改。无需跟踪这些版本。但是一旦数据大约 30 天,我想跟踪它的变化。这可能使用单个时间 table 吗?或者我是否需要拥有包含所有内容的“实时”table 和一个单独的“存档table”,以便我们仅在 30 天的旧数据中进行 ETL 并打开时间?

Or would I need to have my ‘real time’ table with everything in it and a separate ‘archive table’ that we would ETL in only the 30 day old data/datetime and turn the temporal on that on?

您必须使用此方法,因为当您配置时间 tables 时,您无法在某些日期属性上设置 30 天偏移量

因此,正如您在最初的问题中指出的那样,合乎逻辑的解决方法是创建一个计划的进程,该进程将 MERGE 更改为启用了 TEMPORAL TABLE 功能的存档 table,因此它将保持变化的历史。

Is this possible using a single temporal table? Or would I need to have my ‘real time’ table with everything in it and a separate ‘archive table’ that we would ETL in only the 30 day old data and turn the temporal on that on?

创建系统版本时间 table 时,它会自动创建一个以“_history”为后缀的历史记录 table。当系统版本控制开启时,无法从 _history 中删除。简单的答案是关闭版本控制,从 _history table 中删除行,然后重新打开系统版本控制。喜欢this。 SO 和其他站点上有很多文章和示例。