Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
SQL

SQL Server: Fix a Temporal Table History Missing a Dropped Column

- 27.11.26 - ErcanOPAK

🗄️ SQL Server: Fix a Temporal Table History Missing a Dropped Column

System-versioned temporal tables automatically carry every existing column into the history table when versioning is enabled, but dropping a column from the current table later doesn’t retroactively remove it from already-recorded history rows — and depending on how the drop was performed, it can also fail to add that same column back to history in a consistent way if the column is later re-added under the same name with a different type.

🔎 The Problem

ALTER TABLE dbo.Employees DROP COLUMN LegacyBadgeId;
-- Succeeds. Current table: column gone.
-- History table dbo.EmployeesHistory: LegacyBadgeId column
-- still exists with old data, now permanently orphaned - any
-- query joining current + history on SELECT * will error or
-- silently return mismatched schemas depending on the query

✅ Fix: Manage History Schema Changes Deliberately

  • Before dropping a column from a temporal table, decide explicitly whether the history table should keep it (for audit purposes) or also drop it — SQL Server’s automatic behavior here only ever acts on the current table, never on history, unless you tell it to.
  • If the column should also disappear from history, temporarily set SYSTEM_VERSIONING = OFF, drop the column from both tables explicitly, then re-enable versioning with SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.EmployeesHistory) pointing at the now-matching schema.
  • Avoid SELECT * against a temporal table’s history in application code or reports entirely — always list columns explicitly, so a future schema drift between current and history tables fails loudly in development instead of quietly in production.

🚨 Why This Is Dangerous

  • An audit or compliance query that assumes history always mirrors the current table’s schema can silently skip or misreport older records once a column drop has desynced the two, which is exactly the kind of gap that only surfaces during an actual audit, too late to fix quietly.

Temporal tables promise to remember everything, but only for the columns you tell them to keep remembering.

— Database Engineer

Related posts:

SQL Server: Fix a Query Reading Uncommitted Data Because READ_COMMITTED_SNAPSHOT Isn't What You Assu...

SQL Server: Fix a Query Reading Uncommitted Data Because READ_COMMITTED_SNAPSHOT Isn't What You Assu...

Partial Indexes Save Space

Partial Indexes Save Space

SQL Server: Fix a Query That Runs Instantly in SSMS but Times Out From the App Because ARITHABORT De...

SQL Server: Fix a Query That Runs Instantly in SSMS but Times Out From the App Because ARITHABORT De...

Views: 7
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

C#: Fix an Expression Tree Compiling Once Then Caching Stale Data
Git: Fix a Worktree Blocking a Branch Delete It Doesn’t Need

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,079 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 996 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 995 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 866 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 671 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 629 views
  8. 08Average of all values in a column that are not zero in SQL 584 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 561 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com