Has anyone tried prepopulating temporal tables with old history data? Before we decide to use temporal tables we need to be able to import our old history into them.
Sql-server – SQL Server 2016 Temporal Tables
importsql serversql-server-2016temporal-tables
Related Question
- SQL Server 2016 – Temporal Tables and Compressed Indexes
- Sql-server – Temporal tables: history table population
- SQL Server Temporal Tables – Managing Begin and End Dates
- SQL Server 2016 – Temporal Tables Include Current State
- Sql-server – SQL Server Temporal Tables History Table size
- Sql-server – Add a column at a specific position in system versioned temporal table
Best Answer
Yes, you can import old history into history tables. Here is a quick example that shows how to do this - you need to turn off system versioning temporarily.
Now, insert some data:
Validate there is a system-versioned row in history table:
Now, to insert rows into history. Execute these steps one at a time; the parser will prevent the insert if these are all in a single batch.
Now validate there are now two versioned rows of id = 2 in history table: