Lesson 3 of 4 Specialized Tables

Ledger Tables for Tamper Evidence

This lesson explains how ledger tables make data tamper-evident with hashes and external digests, and how they differ from temporal tables and auditing.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how database digests and verification detect tampering.
  • Distinguish between updatable and append-only ledger tables.
  • Choose between ledger, temporal tables and auditing for a requirement.

How ledger works

The ledger feature computes a SHA-256 hash of every row version changed by a transaction and links transactions into blocks, each containing the hash of the previous block, like a blockchain. Periodically, the root hash of the database ledger, the database digest, is exported to trusted storage such as Azure immutable blob storage or Azure Confidential Ledger. Because the digests are outside the database, an administrator who changes rows directly in the data files, or rewrites history, cannot recompute digests that are already stored.

sys.sp_verify_database_ledger (or sp_verify_database_ledger_from_digest_storage) recomputes the hashes and compares them with the stored digests, reporting any tampering. Ledger provides tamper evidence, not tamper prevention: it proves whether data was altered but does not stop someone with permissions from changing it.

The following diagram shows the hash chain and the exported digest.

How ledger works. Each transaction's changed row versions are hashed with SHA-256, and transactions are linked into blocks, each containing the hash of the previous block. The root hash, the database digest, is exported periodically to trusted storage outside the database, such as immutable blob storage or Azure Confidential Ledger. Verification recomputes the hashes and compares them with the stored digests, so tampering is detected; ledger proves alteration but does not prevent it.
Digests outside the database make tampering detectable.

Updatable and append-only ledger tables

An updatable ledger table allows inserts, updates and deletes; it has a history table and a ledger view that shows every operation with its transaction. An append-only ledger table allows only inserts, which suits logs, sensor readings and financial postings that must never change. A ledger database makes every table a ledger table automatically. Ledger tables cannot be converted back to ordinary tables, and dropped ledger tables are kept as dropped ledger tables.

CREATE TABLE Finance.Payments
(
    PaymentID int NOT NULL PRIMARY KEY,
    Amount    decimal(12,2) NOT NULL,
    PaidUtc   datetime2 NOT NULL
)
WITH (SYSTEM_VERSIONING = ON, LEDGER = ON);              -- updatable

CREATE TABLE Finance.AuditEvents
(
    EventID   bigint IDENTITY PRIMARY KEY,
    Detail    nvarchar(400) NOT NULL
)
WITH (LEDGER = ON (APPEND_ONLY = ON));                   -- append-only
Sort into groups

Updatable or append-only?

Exam skills 1.1.2

Choose the ledger table type for each data set.

Log in to try this activity Interactive activities are free with an account.

Ledger compared with temporal tables and auditing

Temporal tables keep history for querying, auditing records who did what, and ledger proves integrity. The following comparison helps choose between them.

Temporal table
PurposeQuery past states
History can be altered by adminsYes, by turning off versioning
Captures valuesYes, full row versions
Choose when Point-in-time reporting
Ledger table
PurposeProve data was not tampered with
History can be altered by adminsDetectable through digests
Captures valuesYes, row versions and hashes
Choose when Regulatory or contractual integrity proof
Auditing
PurposeRecord actions and who performed them
History can be altered by adminsDepends on the audit target's protection
Captures valuesStatements, not necessarily values
Choose when Investigations and compliance reporting
Scenario questions

Temporal, ledger or auditing?

Exam skills 1.1.2 · 2.1.6

Choose the feature that meets each requirement.

Log in to try this activity Interactive activities are free with an account.
Worked example

Proving payment records were not altered

An auditor requires proof that payment records in an Azure SQL database have not been modified by anyone, including database administrators, since they were written. Payments are never updated after insertion. Which design meets the requirement with the least effort?

Create the payments table as an append-only ledger table with automatic digest storage enabled, and run sp_verify_database_ledger when the auditor asks. Append-only matches the insert-only workload and blocks updates and deletes through T-SQL, and the external digests make direct tampering detectable. A temporal table records history but administrators can disable versioning and change it, and auditing records actions without proving the data is intact.

Check yourself

Does a ledger table stop an administrator from updating rows through T-SQL?

Show answer

Not for an updatable ledger table: it records and proves changes rather than preventing them. Only append-only ledger tables block updates and deletes.

Exam Tips

Remember for the exam

  • Tamper evidence, even against administrators: ledger tables with external digest storage.
  • Insert-only data: append-only ledger table; updates allowed: updatable ledger table.
  • Verify integrity: sp_verify_database_ledger.
  • Ledger detects tampering; it does not prevent authorized changes.