Seed data with old dates in Temporal Table - SQL Server -
i need seed data local development purpose in following temporal table, start date should old. given table schema is
create table [dbo].[contact]( [contactid] [uniqueidentifier] not null, [contactnumber] [nvarchar](50) not null, [sequenceid] [int] identity(1,1) not null, [sysstarttime] [datetime2](0) generated row start not null, [sysendtime] [datetime2](0) generated row end not null, constraint [pk_contact] primary key nonclustered ( [contactid] asc )with (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary], period system_time ([sysstarttime], [sysendtime]) ) on [primary] ( system_versioning = on (history_table = [dbo].[contacthistory] , data_consistency_check = on ) )
i need insert old dated data table.
insert dbo.contact ( contactid, contactnumber, --sequenceid - column value auto-generated sysstarttime, sysendtime ) values ( newid(), -- contactid - uniqueidentifier n'9999912345', -- contactnumber - nvarchar -- sequenceid - int '2017-09-01 06:26:59', -- sysstarttime - datetime2 null -- sysendtime - datetime2 )
i'm getting following error.
cannot insert explicit value generated column in table 'devdb.dbo.contact'. use insert column list exclude generated column, or insert default generated column.
kindly assist me how add or update old dataed data temporal table
what trying achieve? generated columns technical columns , if set them can't update them, updated automatically. tracking changes have contacthistory table.
normally supposed use following inserts:
insert dbo.contact ( contactid, --newid() contactnumber ) values ( '045aba61-1c64-4fe4-b079-18a9a50335d5', -- contactid - uniqueidentifier n'9999912345' );
then after first insert have:
select * dbo.contact select * dbo.contacthistory
not have records in history yet doesn't store actual record. if change data, use normal update statements ignoring these generated columns:
update dbo.contact set contactnumber = '123456789' contactid = '045aba61-1c64-4fe4-b079-18a9a50335d5'
let's check data again:
select * dbo.contact select * dbo.contacthistory
now have bit different situation:
as can see actual data updated expected , history table has old record "closed" endtime.
so, if have native support of scd sql server for, not touch these columns. if special reasons need update these columns, not use generated columns , use default constrains that.
Comments
Post a Comment