Hi friends, in this post, we will be discussing about the SQL Server 2022 error message: An existing History Table cannot be specified with LEDGER=ON.
What are Ledger Tables in SQL Server 2022?
Ledger tables are special tables originally introduced in SQL Server 2022.
They constitute a major part of the security enhancements in SQL Server 2022.
Ledger tables, create a track of data modifications over time, and these historical records cannot be modified, since they are encrypted and powered using blockchain technology.
To this end, using Ledger Tables, among other, is an excellent option, when you have tables with sensitive data that need to be frequently audited.
We will extensively talk about SQL Server Ledger Tables in a future article.
For now, let’s proceed and further discuss about the specific error message.
Example that gives the error message:
Now, regarding the error message that we are examining in this post, consider the below example, where we try to create an updateable ledger table in SQL Server 2022.
CREATE TABLE dbo.[EmployeeDetails] ( [EmployeeID] INT NOT NULL PRIMARY KEY CLUSTERED, [FirstName] VARCHAR (50) NOT NULL, [LastName] VARCHAR (50) NOT NULL, [Address] VARCHAR (50) NOT NULL, [EmploymentDate] DATE NOT NULL ) WITH ( SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.[EmployeeDetails]), LEDGER = ON );
If we execute the above T-SQL script in SQL Server 2o22 or later, we will get the below error message:
Msg 37355, Level 16, State 1, Line 3
An existing History Table cannot be specified with LEDGER=ON.
Why we get the error message?
The reason we get the error message, is that we tried to specify as history table, the same table as the original table that we have created. In this example, we have tried to specify the name EmployeeDetails as both the actual and historical (ledger) table.
Example that works
Now, let’s fix the issue with the above script, in order to make it work:
CREATE TABLE dbo.[EmployeeDetails] ( [EmployeeID] INT NOT NULL PRIMARY KEY CLUSTERED, [FirstName] VARCHAR (50) NOT NULL, [LastName] VARCHAR (50) NOT NULL, [Address] VARCHAR (50) NOT NULL, [EmploymentDate] DATE NOT NULL ) WITH ( SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.[EmployeeDetails_History]), LEDGER = ON );
What we fixed in the above code, is that we defined a different name for the history table, since the name for this table, must be different than the actual table.
When we execute the above code, we can see that our updateable ledger table is successfully created.
Learn what’s new in SQL Server 2022. Enroll to the course!
Check our online course titled “SQL Server 2022: What’s New – New and Enhanced Features”
and learn all about the new features and enhancements in SQL server 2022!
(special limited-time discount included in link).
Featured Online Courses:
- SQL Server 2022: What’s New – New and Enhanced Features
- Introduction to Azure Database for MySQL
- Working with Python on Windows and SQL Server Databases
- Boost SQL Server Database Performance with In-Memory OLTP
- Introduction to Azure SQL Database for Beginners
- Essential SQL Server Administration Tips
- SQL Server Fundamentals – SQL Database for Beginners
- Essential SQL Server Development Tips for SQL Developers
- Introduction to Computer Programming for Beginners
- .NET Programming for Beginners – Windows Forms with C#
- SQL Server 2019: What’s New – New and Enhanced Features
- Entity Framework: Getting Started – Complete Beginners Guide
- How to Import and Export Data in SQL Server Databases
- A Guide on How to Start and Monetize a Successful Blog
- Data Management for Beginners – Main Principles
Read Also:
- SQL Server 2022: What’s New – New and Enhanced Features (Course Preview)
- SQL Server 2022 Generally Available!
- SQL Server 2022 Overview: A Hybrid Data Platform
- Query Store Enhancements in SQL Server 2022
- Azure Synapse Link in SQL Server 2022
- Useful Python Programming Tips
- How to Connect to SQL Server Databases from a Python Program
- Working with Python on Windows and SQL Server Databases (Course Preview)
- The multi-part identifier … could not be bound
- Where are temporary tables stored in SQL Server?
- How to Patch a SQL Server Failover Cluster
- Operating System Error 170 (Requested Resource is in use)
- Installing SQL Server 2016 on Windows Server 2012 R2: Rule KB2919355 failed
- The operation failed because either the specified cluster node is not the owner of the group, or the node is not a possible owner of the group
- A connection was successfully established with the server, but then an error occurred during the login process.
- SQL Server 2008 R2 Service Pack Installation Fails – Element not found. (Exception from HRESULT: 0x80070490)
- There is insufficient system memory in resource pool ‘internal’ to run this query.
- Argument data type ntext is invalid for argument …
- Fix: VS Shell Installation has Failed with Exit Code 1638
- Essential SQL Server Development Tips for SQL Developers
- Introduction to Azure Database for MySQL (Course Preview)
- [Resolved] Operand type clash: int is incompatible with uniqueidentifier
- The OLE DB provider “Microsoft.ACE.OLEDB.12.0” has not been registered – How to Resolve it
- SQL Server replication requires the actual server name to make a connection to the server – How to Resolve it
- Issue Adding Node to a SQL Server Failover Cluster – Greyed Out Service Account – How to Resolve
- Data Management for Beginners – Main Principles (Course Preview)
- Resolve SQL Server CTE Error – Incorrect syntax near ‘)’.
- SQL Server is Terminating Because of Fatal Exception 80000003 – How to Troubleshoot
- … more SQL Server troubleshooting articles
Recommended Software Tools
Snippets Generator: Create and modify T-SQL snippets for use in SQL Management Studio, fast, easy and efficiently.
Dynamic SQL Generator: Convert static T-SQL code to dynamic and vice versa, easily and fast.
Get Started with Programming Fast and Easy – Enroll to the Online Course!
Check our online course “Introduction to Computer Programming for Beginners”
(special limited-time discount included in link).Learn the main principles of Computer Programming and get introduced to C, C++, C#, Python, Java and SQL.
Subscribe to our newsletter and stay up to date!
Subscribe to our YouTube channel (SQLNetHub TV)
Easily generate snippets with Snippets Generator!
Secure your databases using DBA Security Advisor!
Generate dynamic T-SQL scripts with Dynamic SQL Generator!
Check our latest software releases!
Check our eBooks!
Rate this article:
Reference: SQLNetHub.com (https://www.sqlnethub.com)
© SQLNetHub
Artemakis Artemiou, a distinguished Senior Database and Software Architect, brings over 20 years of expertise to the IT industry. A Certified Database, Cloud, and AI professional, he earned the Microsoft Data Platform MVP title for nine consecutive years (2009-2018). As the founder of SQLNetHub and GnoelixiAI Hub, Artemakis is dedicated to sharing his knowledge and democratizing education on various fields such as: Databases, Cloud, AI, and Software Development. His commitment to simplicity and knowledge sharing defines his impactful presence in the tech community.