Search code examples
sql-servertemporal-tables

SQL Server - Temporal Table - Storage costs


Are there any information on the internet, where I can verify how much storage costs are for temporal tables?

Will the server create a the full hardcopy of the row/tuple that was modified? Or will the server use a reference/link to the original values of the master table that are not modified?

Example:

  • I have a row with 10 columns = storage 100 KB.
  • I change one value of that row, two times.
  • I now have two rows in the historical table after changes.
  • Is the storage cost for the master and historical table then ~300KB?

Thanks for every hint!


Solution

  • Will the server creates a the full hardcopy of the row/tuple that was modified? Or will the server use a reference/links to the original values of the master table that are not modified?

    Here is the cite of the book Pro SQL Server Internals by Dmitri Korotkevitch that ansers your question:

    In a nutshell, each temporal table consists of two tables — the current table with the current data, and a history table that stores old versions of the rows. Every time you modify or delete data in the current table, SQL Server adds an original version of those rows to the history table.

    A current table should always have a primary key defined. Moreover, both current and history tables should have two datetime2 columns, called period columns, that indicate the lifetime of the row. SQL Server populates these columns automatically based on transaction start time when the new versions of the rows were created. When a row has been modified several times in one transaction, SQL Server does not preserve uncommitted intermediary row versions in the history table.

    SQL Server places the history tables in a default filegroup, creating non-unique clustered indexes on the two datetime2 columns that control row lifetime. It does not create any other indexes on the table.

    In both the Enterprise and Developer Editions, history tables use page compression by default.

    So it's not

    reference/links to the original values of the master table

    Previous row version is just copied as it is into historical table on every mofification.