clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 1228830 fiddles created (16648 in the last week).

-- https://dba.stackexchange.com/a/257921/68127 -- https://dba.stackexchange.com/a/219829/68127 create table foo ( Id int not null constraint pk_foo primary key, Value int not null, BeginDate datetime2(0) not null, EndDate datetime2(0) not null ); create table foo_history ( Id int not null, Value int not null, BeginDate datetime2(0) not null, EndDate datetime2(0) not null ); insert foo values ( 1, 10, '2019-12-24', '9999-12-31 23:59:59.9999999' ); insert foo_history values ( 1, 20, '2019-12-05', '2019-12-23 23:59:59.9999999' ), ( 1, 40, '2019-11-05', '2019-12-04 23:59:59.9999999' );
3 rows affected
 hidden batch(es)


alter table foo add period for system_time (BeginDate, EndDate); alter table foo set (system_versioning = on (history_table = dbo.foo_history));
 hidden batch(es)


select * from foo; select * from foo_history;
Id Value BeginDate EndDate
1 10 2019-12-24 00:00:00.0000000 9999-12-31 23:59:59.0000000
Id Value BeginDate EndDate
1 20 2019-12-05 00:00:00.0000000 2019-12-24 00:00:00.0000000
1 40 2019-11-05 00:00:00.0000000 2019-12-05 00:00:00.0000000
 hidden batch(es)


select * from foo for system_time all;
Id Value BeginDate EndDate
1 10 2019-12-24 00:00:00.0000000 9999-12-31 23:59:59.0000000
1 20 2019-12-05 00:00:00.0000000 2019-12-24 00:00:00.0000000
1 40 2019-11-05 00:00:00.0000000 2019-12-05 00:00:00.0000000
 hidden batch(es)