columns filter in system versioned temporal table

Surendra Adhikari 211 Reputation points
2021-07-27T03:50:28.34+00:00

Can we log changes only in certain columns, not in all, in the history table of system versioned temporal table? In a table there are some columns for which data changes more frequently which I dont need to log because logging those changes increased data size enormously. Or can we remove the log of those changes? I only need to log changes in other columns for which data changes less frequently. Is there a way to achieve this?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,788 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Cris Zhan-MSFT 6,626 Reputation points
    2021-07-27T06:03:20.647+00:00

    Hi,

    The history table must always be schema-aligned with the current or temporal table, in terms of number of columns, column names, ordering and data types.
    https://learn.microsoft.com/en-us/sql/relational-databases/tables/creating-a-system-versioned-temporal-table?view=sql-server-ver15

    I tried to create a temporal table with a user-defined history table, and made a column name of the history table inconsistent with the temporal table. But I got following error.

    Msg 13524, Level 16, State 1, Line 18
    Setting SYSTEM_VERSIONING to ON failed because column 'SysEndTime2' at ordinal 6 in history table 'test02.dbo.DepartmentHistory' has a different name than the column 'SysEndTime' at the same ordinal in table 'test02.dbo.Department'.

    Manage retention of historical data in system-versioned temporal tables
    https://learn.microsoft.com/en-us/sql/relational-databases/tables/manage-retention-of-historical-data-in-system-versioned-temporal-tables?view=sql-server-ver15

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.