Cannot Delete Rows From A Temporal History Table In SQL Server
Given that you'll have to delete records from an SQL server history table, you might come across with the issue as mentioned in the title of the post.
After doing some research and experiments, there are three steps to delete records from a temporal history table.
a. First is to remove the main table's System Versioning option.
b. Next is to delete the records of the temporal history table.
c. Then Set again the system versioning and history table of the main table.
Solved.. :-)
a. First is to remove the main table's System Versioning option.
ALTER TABLE [dbo].[tblParts] SET ( SYSTEM_VERSIONING = OFF )
Delete from dbo.tblPartsHistory WITH (TABLOCKX);
ALTER TABLE [dbo].[tblParts] SET ( SYSTEM_VERSIONING = ON (HISTORY_TABLE = [dbo].[tblPartsHistory]))
Solved.. :-)
Comments
Post a Comment