Friday, December 13, 2024

Temporal Tables FAQ

I had the pleasure of presenting Temporal Tables to the Capital Area .NET User Group on December 10, 2024.  Some interesting FAQ arose from that meeting so I thought it would be good to share it on my blog for reference.

 

  1. Is the historical table logged to the Transaction log in the same way a conventional table is?  Will we “see” the inserts in the Tran log the same way we see them for a normal table?

No

 

  1. Are Temporal Tables available in Azure?

Yes, in Azure SQL Database and Azure SQL Managed Instance

 

  1. Will Temporal Tables work with graph tables?

No, Node and edge tables can't be created as system-versioned temporal tables

Ref: https://learn.microsoft.com/en-us/sql/relational-databases/graphs/sql-graph-architecture?view=sql-server-ver16

 

  1. What triggers the purge of SQL Server Temporal Tables?

A background task is created to perform aged data cleanup for all temporal tables with finite retention period.

ref: https://learn.microsoft.com/en-us/azure/azure-sql/database/temporal-tables-retention-policy?view=azuresql

 

  1. Can I modify recs in the history table with versioning OFF? 

Yes

 

  1. Can I alter the current table with versioning ON? 

Yes, alters both tables simultaneously

 

  1. Does EF Code First Support Temporal Tables (TT)?

Yes, EF Core 6.0 and later supports:

  • The creation of temporal tables using Migrations
  • Transformation of existing tables into temporal tables, again using Migrations
  • Querying historical data
  • Restoring data from some point in the past

 

  1. When are Temporal Tables NOT a good fit? 

For Static data where a user can't change a field.

The following industries rarely, if ever, are users allowed to delete any data

  • Financial services (i.e. stock purchases, banking)
  • Purchases
  • GPS Location Tracking
  • Fraud Detection(Location of purchases, IP/location of login)
  • Tracking appointments (Resolve Customer service issues)
  • Car Rental company, tracking owner and mileage when vehicle was in possession
  • Hotel room rental
  • Airline seat charts, who sat where in which flight

 

  1. Are there other approaches are available for managing historical data in the temporal history table?

Yes, The following four methods are available:

    1. Stretch Database
    2. Table Partitioning
    3. Custom Cleanup Script
    4. Retention Policy

 

  1. Can Temporal tables be used with partitioned databases?

Yes, with some limitations. If current table is partitioned, the history table is created on default file group because partitioning configuration is not replicated automatically from the current table to the history table.

 

  1. Can the temporal table be placed in another DB?

No, History table must be created in the same database as the current table.

However, it can be placed in a different schema within the same database.

Also, Temporal querying over Linked Server is not supported.

 

  1. Can it be used with Elastic DBs?

Yes

 

  1. Can I alter table schema with sys versioning = on? 

No

 

  1. Can I add additional fields to History table?

No, fields and field nullability must be identical

 

  1. Is there automatic truncation of history table?

Yes, using HISTORY_RETENTION_PERIOD = 6 MONTHS