Microsoft Dev Blogs

Using Ledger in Azure SQL Database

thumbnail

Ledger in Azure SQL Database

Ledger in Azure SQL Database provides a history of records in your database, maintaining previous values of updated or deleted rows in a history table. This feature can be enabled database-wide and creates Updatable Ledger Tables, which are system-versioned tables.

To create an Updatable Ledger Table, use the SYSTEM_VERSIONING clause and specify the ledger-related columns to be added to the table structure. For each updatable ledger table, a view is created that contains the ledger-related columns.

Inserting or deleting a row in the ledger table produces a new row in the ledger view that contains the transaction ID and sequence number. Updating a row also creates a new row in the ledger view.

Creating an Append-Only Ledger Table is similar to the Updatable table, but with the WITH (LEDGER = ON (APPEND_ONLY = ON )) clause. This table type allows for only inserting new rows and does not support updates or deletes.

Transactions in a ledger-enabled table are SHA-256 hashed and maintained in a Merkle tree data structure. The latest block's hash in the database ledger is called the database digest.

Overall, Ledger in Azure SQL Database is a powerful feature that helps ensure data integrity and security.