I'm trying to tell a history table that a certain record is "relevant" in a different time span than its original ValidFrom
and ValidTo
values, like so:
ALTER TABLE dbo.statusForStudents SET (SYSTEM_VERSIONING = OFF);
update history.statusForStudents set validfrom='2020-10-25 11:12:07.40',ValidTo='2020-10-26 12:48:31.19' where ValidFrom='2020-12-03 11:12:07.40' and id=1066255
ALTER TABLE statusForStudents
SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE =history.statusForStudents));
That is:
I turn off TT,
update the relevant record,
and turn on TT again.
And this actually works, However, when I update the current value, after TT in on again:
update statusForStudents set PrimaryStatusID=1 where id=1066255
It seems that the TT mechanism, for some reason "skips" a few seconds between the previous ValidTo
time, and the next ValidFrom
:
I've never seen a gap like that in history tables..
Is this a bug?
Is there a way to overcome it?
Explanation
This would make sense if the history row that you updated was valid from
2020-12-03 11:12:07.40
to2020-12-03 12:12.67
. The start time does match with your history update statement...Reproduction
Create temporal table
Create some history to play with
This gives me:
Mess with the history
New update
This gives me:
There now appears to be a 2 second gap between the rows with status 1 and 3 in the history table. However, this is exactly the row with a 2 second duration (status = 100) that was updated. In this case the "gap" was introduced by the history update.
Conclusion
Manually updating the history table requires the update of adjacent rows in the history table to avoid gaps and overlaps. Most likely on both the place where the history row is moved from and the place where the row is moved to.
Fiddle to see it in action.