From 24f7666278bcba19be8c20ae4e7707186b65f372 Mon Sep 17 00:00:00 2001 From: Sergio Govoni Date: Sun, 7 Dec 2025 18:44:14 +0100 Subject: [PATCH 01/10] Initial commit create-configure-optimizedlocking-db.sql --- .../create-configure-optimizedlocking-db.sql | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 samples/features/optimized-locking/transaction-id-locking/sql-scripts/create-configure-optimizedlocking-db.sql diff --git a/samples/features/optimized-locking/transaction-id-locking/sql-scripts/create-configure-optimizedlocking-db.sql b/samples/features/optimized-locking/transaction-id-locking/sql-scripts/create-configure-optimizedlocking-db.sql new file mode 100644 index 0000000000..4b29a8ac3a --- /dev/null +++ b/samples/features/optimized-locking/transaction-id-locking/sql-scripts/create-configure-optimizedlocking-db.sql @@ -0,0 +1,43 @@ +------------------------------------------------------------------------ +-- Run this script on a SQL Server 2025 instance (or higher) to -- +-- create a database named OptimizedLocking if it doesn't exists -- +------------------------------------------------------------------------ + +USE [master]; +GO + +CREATE DATABASE [OptimizedLocking]; +GO + +ALTER DATABASE [OptimizedLocking] SET COMPATIBILITY_LEVEL = 170; +ALTER DATABASE [OptimizedLocking] SET RECOVERY SIMPLE; +ALTER DATABASE [OptimizedLocking] SET PAGE_VERIFY CHECKSUM; +ALTER DATABASE [OptimizedLocking] SET ACCELERATED_DATABASE_RECOVERY = ON; +ALTER DATABASE [OptimizedLocking] SET READ_COMMITTED_SNAPSHOT ON; +ALTER DATABASE [OptimizedLocking] SET OPTIMIZED_LOCKING = ON; + +USE [OptimizedLocking] +GO + +IF NOT EXISTS ( + SELECT + [name] + FROM + sys.filegroups + WHERE + (is_default = 1) + AND ([name] = N'PRIMARY') + ) + ALTER DATABASE [OptimizedLocking] MODIFY FILEGROUP [PRIMARY] DEFAULT; +GO + +SELECT + [name] + ,ADR = is_accelerated_database_recovery_on + ,RCSI = is_read_committed_snapshot_on + ,OL = is_optimized_locking_on +FROM + sys.databases +WHERE + [name] = DB_NAME(); +GO \ No newline at end of file From 0b3cc1cec9c41713fad1303965b8a1b944817e69 Mon Sep 17 00:00:00 2001 From: Sergio Govoni Date: Sun, 7 Dec 2025 19:02:13 +0100 Subject: [PATCH 02/10] Initial commit of Optimized Locking TID sample README --- .../transaction-id-locking/README.md | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 samples/features/optimized-locking/transaction-id-locking/README.md diff --git a/samples/features/optimized-locking/transaction-id-locking/README.md b/samples/features/optimized-locking/transaction-id-locking/README.md new file mode 100644 index 0000000000..f3f7ba87a9 --- /dev/null +++ b/samples/features/optimized-locking/transaction-id-locking/README.md @@ -0,0 +1,137 @@ + +![](https://github.com/microsoft/sql-server-samples/blob/master/media/solutions-microsoft-logo-small.png) + +# SQL Server 2025 Optimized Locking: Transaction ID (TID) Locking internals + +This sample describes how to read and interpret the Transaction ID stored in row data pages. + +## Background + +Optimized Locking is a SQL Server 2025 database engine feature designed to reduce the memory used for lock management, decrease the phenomenon known as lock escalation, and increase workload concurrency. + +Optimized Locking depends on two technologies that have long been part of the SQL Server engine: +- [Accelerated Database Recovery (ADR)](https://learn.microsoft.com/sql/relational-databases/accelerated-database-recovery-concepts) is a required prerequisite for enabling Optimized Locking +- [Read Committed Snapshot Isolation (RCSI)](https://learn.microsoft.com/sql/t-sql/statements/set-transaction-isolation-level-transact-sql) is not a strict requirement, but allows full benefit from Optimized Locking + +Optimized Locking is based on two key mechanisms: +- Transaction ID (TID) locking +- Lock After Qualification (LAQ) + +### What is the Transaction ID? + +The Transaction ID (TID) is a unique transaction identifier. + +When a [row-versioning based isolation level](https://learn.microsoft.com/en-us/sql/relational-databases/sql-server-transaction-locking-and-row-versioning-guide#Row_versioning) is active, or when [Accelerated Database Recovery (ADR)](https://learn.microsoft.com/sql/relational-databases/accelerated-database-recovery-concepts) is enabled, every row in the database internally contains a transaction identifier. + +The TID is stored on disk in the additional 14 bytes that are associated with each row when features such as RCSI or ADR are enabled. + +Every transaction that modifies a row, it tags that row with its own TID, so each row in the database is labeled with the last TID that modified it. + + +### Contents + +[About this sample](#about-this-sample)
+[Before you begin](#before-you-begin)
+[Run this sample](#run-this-sample)
+[Sample Details](#sample-details)
+[Disclaimers](#disclaimers)
+[Related links](#related-links)
+ + +## About this sample + +- **Applies to:** SQL Server 2025 (or higher) +- **Key features:** SQL Server 2025 Optimized Locking +- **Workload:** No workload related to this sample +- **Programming Language:** T-SQL +- **Authors:** [Sergio Govoni](https://www.linkedin.com/in/sgovoni/) | [Microsoft MVP Profile](https://mvp.microsoft.com/mvp/profile/c7b770c0-3c9a-e411-93f2-9cb65495d3c4) | [Blog](https://segovoni.medium.com/) | [GitHub](https://github.com/segovoni) | [Twitter](https://twitter.com/segovoni) + + +## Before you begin + +To run this sample, you need the following prerequisites. + +**Software prerequisites:** + +1. SQL Server 2025 (or higher) + + +## Run this sample + +### Setup code + +1. Download [create-configure-optimizedlocking-db.sql T-SQL script](sql-scripts) from sql-scripts folder +2. Check if a database called OptimizedLocking does not exist in your SQL Server 2025 instance +3. Execute create-configure-optimizedlocking-db.sql script on your SQL Server 2025 instance +4. Run the commands described in the sample details section + + +## Sample Details + +Currently, the only way to read the Transaction ID of a row is by using the `DBCC PAGE` command. + +Let's consider the table dbo.TelemetryPacket, with the schema defined in the following T-SQL code snippet. + +```sql +USE [OptimizedLocking] +GO + +CREATE TABLE dbo.TelemetryPacket +( + PacketID INT IDENTITY(1, 1) + ,Device CHAR(8000) DEFAULT ('Something') +); +GO +``` + +The table schema is designed so that each row occupies exactly one data page. + +Insert three rows with default values into the dbo.TelemetryPacket table. Note that this is done in a single transaction. + +```sql +BEGIN TRANSACTION +INSERT INTO dbo.TelemetryPacket DEFAULT VALUES; +INSERT INTO dbo.TelemetryPacket DEFAULT VALUES; +INSERT INTO dbo.TelemetryPacket DEFAULT VALUES; +COMMIT +``` + +Let's explore the content of the dbo.TelemetryPacket table, enriched with the PageId column, which shows the result of the undocumented function sys.fn_PhysLocFormatter. Use this function to correlate the rows returned by the `SELECT` with their physical location on disk. + +```sql +USE [OptimizedLocking] +GO + +SELECT + * + ,PageId = sys.fn_PhysLocFormatter(%%physloc%%) +FROM + dbo.TelemetryPacket; +``` + +The values shown in the PageId column represent the physical location of the data. + +Let's look at the row where PacketID equals 1. + +The value (1:XXXX:0) in the PageId column is composed of three parts separated by ":". Here is what each part represents: +- 1 is the numeric identifier of the database file (file number) where the page is located +- XXXX is the page number inside file 1 of the database +- 0 is the slot number + +Use the `DBCC PAGE` command to inspect the TID of page XXXX. + +```sql +DBCC PAGE ('OptimizedLocking', 1, XXXX, 3); +``` + +The value of the unique transaction identifier (TID) that modified the row with PacketID equal to 1 is in the Version Information section, under the Transaction Timestamp attribute. + + +## Disclaimers + +The code included in this sample is not intended to be a set of best practices on how to build scalable enterprise grade applications. This is beyond the scope of this sample. + + +## Related Links + +- [Optimized locking](https://learn.microsoft.com/sql/relational-databases/performance/optimized-locking) From 5d9a85810977b4e458bf7402518caa26af97d843 Mon Sep 17 00:00:00 2001 From: Sergio Govoni Date: Sun, 7 Dec 2025 19:37:53 +0100 Subject: [PATCH 03/10] Add examples and output to optimized-locking README.md --- .../transaction-id-locking/README.md | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/samples/features/optimized-locking/transaction-id-locking/README.md b/samples/features/optimized-locking/transaction-id-locking/README.md index f3f7ba87a9..7ad90fab00 100644 --- a/samples/features/optimized-locking/transaction-id-locking/README.md +++ b/samples/features/optimized-locking/transaction-id-locking/README.md @@ -109,22 +109,42 @@ FROM dbo.TelemetryPacket; ``` +The output is similar to the following, except to the values in PageId column. + +| PageId | PacketID | Device | +| ----------- | --------- | --------- | +| (1:2456:0) | 1 | Something | +| (1:2457:0) | 2 | Something | +| (1:2458:0) | 3 | Something | + The values shown in the PageId column represent the physical location of the data. Let's look at the row where PacketID equals 1. -The value (1:XXXX:0) in the PageId column is composed of three parts separated by ":". Here is what each part represents: +The value (1:2456:0) in the PageId column is composed of three parts separated by ":". Here is what each part represents: - 1 is the numeric identifier of the database file (file number) where the page is located -- XXXX is the page number inside file 1 of the database +- 2456 is the page number inside file 1 of the database - 0 is the slot number -Use the `DBCC PAGE` command to inspect the TID of page XXXX. +Use the `DBCC PAGE` command to inspect the TID of page 2456. + +```sql +DBCC PAGE ('OptimizedLocking', 1, 2456, 3); +``` + +The value of the unique transaction identifier (TID) that modified the row with PacketID equal to 1 is in the **Version Information** section, under the **Transaction Timestamp** attribute, as shown in the following sample data. ```sql -DBCC PAGE ('OptimizedLocking', 1, XXXX, 3); +Version Information = + Transaction Timestamp: 985 + Version Pointer: Null +Slot 0 Column 1 Offset 0x4 Length 4 Length (physical) 4 +PacketID = 1 +Slot 0 Column 2 Offset 0x8 Length 8000 Length (physical) 8000 +Device = Something… ``` -The value of the unique transaction identifier (TID) that modified the row with PacketID equal to 1 is in the Version Information section, under the Transaction Timestamp attribute. +TID 985 represents the identifier of the transaction that inserted the rows; every subsequent change to the table rows will update the TID. ## Disclaimers From e4ddffc4b94f791b03c6f3d99089708b22f63c1c Mon Sep 17 00:00:00 2001 From: Sergio Govoni Date: Sun, 7 Dec 2025 19:46:39 +0100 Subject: [PATCH 04/10] Add Optimized Locking section --- samples/features/readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/samples/features/readme.md b/samples/features/readme.md index 079341dcd5..08d413ca52 100644 --- a/samples/features/readme.md +++ b/samples/features/readme.md @@ -32,6 +32,10 @@ Graph tables enable you to add a non-relational capability to your database. The SQL Server Management Objects (SMO) Framework is a set of objects designed for programmatic management of Microsoft SQL Server and Microsoft Azure SQL Database. These code snippets demonstrate features of SMO and illustrate how to use SMO properties and collections without sacrificing performance. +[Optimized Locking](optimized-locking) + +Optimized Locking offers an improved transaction locking mechanism to reduce lock blocking and lock memory consumption for concurrent transactions. + ## Samples for Business Intelligence features within SQL Server [Reporting Services (SSRS)](reporting-services) From 5f8d3d8771dbd2a9aa7e23d34f237392814a9ddf Mon Sep 17 00:00:00 2001 From: Sergio Govoni Date: Sun, 7 Dec 2025 19:53:02 +0100 Subject: [PATCH 05/10] Simplify and enhance optimized-locking README.md --- .../transaction-id-locking/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/samples/features/optimized-locking/transaction-id-locking/README.md b/samples/features/optimized-locking/transaction-id-locking/README.md index 7ad90fab00..7e578ab14b 100644 --- a/samples/features/optimized-locking/transaction-id-locking/README.md +++ b/samples/features/optimized-locking/transaction-id-locking/README.md @@ -1,13 +1,13 @@ ![](https://github.com/microsoft/sql-server-samples/blob/master/media/solutions-microsoft-logo-small.png) -# SQL Server 2025 Optimized Locking: Transaction ID (TID) Locking internals +# Optimized Locking: Transaction ID (TID) Locking internals This sample describes how to read and interpret the Transaction ID stored in row data pages. ## Background -Optimized Locking is a SQL Server 2025 database engine feature designed to reduce the memory used for lock management, decrease the phenomenon known as lock escalation, and increase workload concurrency. +Optimized Locking is a database engine feature designed to reduce the memory used for lock management, decrease the phenomenon known as lock escalation, and increase workload concurrency. Optimized Locking depends on two technologies that have long been part of the SQL Server engine: - [Accelerated Database Recovery (ADR)](https://learn.microsoft.com/sql/relational-databases/accelerated-database-recovery-concepts) is a required prerequisite for enabling Optimized Locking @@ -27,7 +27,6 @@ The TID is stored on disk in the additional 14 bytes that are associated with ea Every transaction that modifies a row, it tags that row with its own TID, so each row in the database is labeled with the last TID that modified it. - ### Contents [About this sample](#about-this-sample)
@@ -41,7 +40,7 @@ Every transaction that modifies a row, it tags that row with its own TID, so eac ## About this sample - **Applies to:** SQL Server 2025 (or higher) -- **Key features:** SQL Server 2025 Optimized Locking +- **Key features:** Optimized Locking - **Workload:** No workload related to this sample - **Programming Language:** T-SQL - **Authors:** [Sergio Govoni](https://www.linkedin.com/in/sgovoni/) | [Microsoft MVP Profile](https://mvp.microsoft.com/mvp/profile/c7b770c0-3c9a-e411-93f2-9cb65495d3c4) | [Blog](https://segovoni.medium.com/) | [GitHub](https://github.com/segovoni) | [Twitter](https://twitter.com/segovoni) @@ -60,9 +59,9 @@ To run this sample, you need the following prerequisites. ### Setup code -1. Download [create-configure-optimizedlocking-db.sql T-SQL script](sql-scripts) from sql-scripts folder -2. Check if a database called OptimizedLocking does not exist in your SQL Server 2025 instance -3. Execute create-configure-optimizedlocking-db.sql script on your SQL Server 2025 instance +1. Download [create-configure-optimizedlocking-db.sql](sql-scripts) T-SQL script from sql-scripts folder +2. Check if a database called OptimizedLocking does not exist in your SQL Server instance +3. Execute create-configure-optimizedlocking-db.sql script on your SQL Server instance 4. Run the commands described in the sample details section @@ -138,6 +137,7 @@ The value of the unique transaction identifier (TID) that modified the row with Version Information = Transaction Timestamp: 985 Version Pointer: Null + Slot 0 Column 1 Offset 0x4 Length 4 Length (physical) 4 PacketID = 1 Slot 0 Column 2 Offset 0x8 Length 8000 Length (physical) 8000 From 51b09937a90cb00db0fc1edaff72f1bc385ae1e3 Mon Sep 17 00:00:00 2001 From: Sergio Govoni Date: Sun, 7 Dec 2025 19:54:59 +0100 Subject: [PATCH 06/10] Cosmetic care --- .../features/optimized-locking/transaction-id-locking/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/features/optimized-locking/transaction-id-locking/README.md b/samples/features/optimized-locking/transaction-id-locking/README.md index 7e578ab14b..88fa780f93 100644 --- a/samples/features/optimized-locking/transaction-id-locking/README.md +++ b/samples/features/optimized-locking/transaction-id-locking/README.md @@ -1,7 +1,7 @@ ![](https://github.com/microsoft/sql-server-samples/blob/master/media/solutions-microsoft-logo-small.png) -# Optimized Locking: Transaction ID (TID) Locking internals +# Optimized Locking: Transaction ID (TID) locking internals This sample describes how to read and interpret the Transaction ID stored in row data pages. From 637860988cd44e3765713f945e53729e37ba0236 Mon Sep 17 00:00:00 2001 From: Sergio Govoni Date: Sun, 7 Dec 2025 19:58:02 +0100 Subject: [PATCH 07/10] Update Twitter to X --- .../features/optimized-locking/transaction-id-locking/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/features/optimized-locking/transaction-id-locking/README.md b/samples/features/optimized-locking/transaction-id-locking/README.md index 88fa780f93..55878c4c04 100644 --- a/samples/features/optimized-locking/transaction-id-locking/README.md +++ b/samples/features/optimized-locking/transaction-id-locking/README.md @@ -43,7 +43,7 @@ Every transaction that modifies a row, it tags that row with its own TID, so eac - **Key features:** Optimized Locking - **Workload:** No workload related to this sample - **Programming Language:** T-SQL -- **Authors:** [Sergio Govoni](https://www.linkedin.com/in/sgovoni/) | [Microsoft MVP Profile](https://mvp.microsoft.com/mvp/profile/c7b770c0-3c9a-e411-93f2-9cb65495d3c4) | [Blog](https://segovoni.medium.com/) | [GitHub](https://github.com/segovoni) | [Twitter](https://twitter.com/segovoni) +- **Authors:** [Sergio Govoni](https://www.linkedin.com/in/sgovoni/) | [Microsoft MVP Profile](https://mvp.microsoft.com/mvp/profile/c7b770c0-3c9a-e411-93f2-9cb65495d3c4) | [Blog](https://segovoni.medium.com/) | [GitHub](https://github.com/segovoni) | [X](https://twitter.com/segovoni) ## Before you begin From bcf3bdc308006dcd90cd0307fdf767c725ba1237 Mon Sep 17 00:00:00 2001 From: Sergio Govoni Date: Mon, 8 Dec 2025 01:05:16 +0100 Subject: [PATCH 08/10] Enhance README with grammar corrections, clearer explanations, and better formatting --- .../transaction-id-locking/README.md | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/samples/features/optimized-locking/transaction-id-locking/README.md b/samples/features/optimized-locking/transaction-id-locking/README.md index 55878c4c04..f99ab17fc9 100644 --- a/samples/features/optimized-locking/transaction-id-locking/README.md +++ b/samples/features/optimized-locking/transaction-id-locking/README.md @@ -3,7 +3,7 @@ # Optimized Locking: Transaction ID (TID) locking internals -This sample describes how to read and interpret the Transaction ID stored in row data pages. +This sample describes how to read and interpret the Transaction ID (TID) stored in row data pages. ## Background @@ -17,7 +17,7 @@ Optimized Locking is based on two key mechanisms: - Transaction ID (TID) locking - Lock After Qualification (LAQ) -### What is the Transaction ID? +### What is the Transaction ID (TID)? The Transaction ID (TID) is a unique transaction identifier. @@ -25,7 +25,7 @@ When a [row-versioning based isolation level](https://learn.microsoft.com/en-us/ The TID is stored on disk in the additional 14 bytes that are associated with each row when features such as RCSI or ADR are enabled. -Every transaction that modifies a row, it tags that row with its own TID, so each row in the database is labeled with the last TID that modified it. +Every transaction that modifies a row tags that row with its own TID, so each row in the database is labeled with the last TID that modified it. ### Contents @@ -59,15 +59,15 @@ To run this sample, you need the following prerequisites. ### Setup code -1. Download [create-configure-optimizedlocking-db.sql](sql-scripts) T-SQL script from sql-scripts folder -2. Check if a database called OptimizedLocking does not exist in your SQL Server instance +1. Download [create-configure-optimizedlocking-db.sql](sql-scripts/create-configure-optimizedlocking-db.sql) T-SQL script from sql-scripts folder +2. Verify that a database named OptimizedLocking does not already exist in your SQL Server instance 3. Execute create-configure-optimizedlocking-db.sql script on your SQL Server instance 4. Run the commands described in the sample details section ## Sample Details -Currently, the only way to read the Transaction ID of a row is by using the `DBCC PAGE` command. +Currently, the only way to read the TID of a row is by using the `DBCC PAGE` command. Let's consider the table dbo.TelemetryPacket, with the schema defined in the following T-SQL code snippet. @@ -108,7 +108,7 @@ FROM dbo.TelemetryPacket; ``` -The output is similar to the following, except to the values in PageId column. +The output is similar to the following, except for the values in the PageId column. | PageId | PacketID | Device | | ----------- | --------- | --------- | @@ -116,22 +116,24 @@ The output is similar to the following, except to the values in PageId column. | (1:2457:0) | 2 | Something | | (1:2458:0) | 3 | Something | -The values shown in the PageId column represent the physical location of the data. +Each value in the PageId column follows the format **(FileID:PageID:SlotID)** and represents the physical location of the data. -Let's look at the row where PacketID equals 1. - -The value (1:2456:0) in the PageId column is composed of three parts separated by ":". Here is what each part represents: -- 1 is the numeric identifier of the database file (file number) where the page is located -- 2456 is the page number inside file 1 of the database -- 0 is the slot number +Let's examine the row where PacketID equals 1. The value (1:2456:0) is composed of three parts separated by ":". Here is what each part represents: +- **1** - the numeric identifier of the database file (FileID) +- **2456** - the page number within the file (PageID) +- **0** - the slot number on the page (SlotID) Use the `DBCC PAGE` command to inspect the TID of page 2456. ```sql +-- Enable trace flag for DBCC PAGE output +DBCC TRACEON(3604); +GO + DBCC PAGE ('OptimizedLocking', 1, 2456, 3); ``` -The value of the unique transaction identifier (TID) that modified the row with PacketID equal to 1 is in the **Version Information** section, under the **Transaction Timestamp** attribute, as shown in the following sample data. +The value of the unique TID that modified the row with PacketID equal to 1 is in the **Version Information** section, under the **Transaction Timestamp** attribute, as shown in the following sample data. ```sql Version Information = @@ -151,7 +153,9 @@ TID 985 represents the identifier of the transaction that inserted the rows; eve The code included in this sample is not intended to be a set of best practices on how to build scalable enterprise grade applications. This is beyond the scope of this sample. +> **Note:** The `DBCC PAGE` command is undocumented and intended for troubleshooting and diagnostic purposes only. It should not be used in production environments without proper understanding and testing. + ## Related Links -- [Optimized locking](https://learn.microsoft.com/sql/relational-databases/performance/optimized-locking) +- [Optimized locking](https://learn.microsoft.com/sql/relational-databases/performance/optimized-locking) \ No newline at end of file From e928c61704fd6a8f9eb936e34819becc0971b360 Mon Sep 17 00:00:00 2001 From: Sergio Govoni Date: Mon, 8 Dec 2025 01:26:24 +0100 Subject: [PATCH 09/10] Improve OptimizedLocking database setup script --- .../create-configure-optimizedlocking-db.sql | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/samples/features/optimized-locking/transaction-id-locking/sql-scripts/create-configure-optimizedlocking-db.sql b/samples/features/optimized-locking/transaction-id-locking/sql-scripts/create-configure-optimizedlocking-db.sql index 4b29a8ac3a..b12de88a63 100644 --- a/samples/features/optimized-locking/transaction-id-locking/sql-scripts/create-configure-optimizedlocking-db.sql +++ b/samples/features/optimized-locking/transaction-id-locking/sql-scripts/create-configure-optimizedlocking-db.sql @@ -1,6 +1,6 @@ ------------------------------------------------------------------------ -- Run this script on a SQL Server 2025 instance (or higher) to -- --- create a database named OptimizedLocking if it doesn't exists -- +-- create a database named OptimizedLocking if it doesn't exist -- ------------------------------------------------------------------------ USE [master]; @@ -15,6 +15,7 @@ ALTER DATABASE [OptimizedLocking] SET PAGE_VERIFY CHECKSUM; ALTER DATABASE [OptimizedLocking] SET ACCELERATED_DATABASE_RECOVERY = ON; ALTER DATABASE [OptimizedLocking] SET READ_COMMITTED_SNAPSHOT ON; ALTER DATABASE [OptimizedLocking] SET OPTIMIZED_LOCKING = ON; +GO USE [OptimizedLocking] GO @@ -28,16 +29,18 @@ IF NOT EXISTS ( (is_default = 1) AND ([name] = N'PRIMARY') ) +BEGIN ALTER DATABASE [OptimizedLocking] MODIFY FILEGROUP [PRIMARY] DEFAULT; -GO +END; SELECT - [name] - ,ADR = is_accelerated_database_recovery_on - ,RCSI = is_read_committed_snapshot_on - ,OL = is_optimized_locking_on + [name] AS DatabaseName + ,is_accelerated_database_recovery_on AS [ADR Enabled] + ,is_read_committed_snapshot_on AS [RCSI Enabled] + ,is_optimized_locking_on AS [Optimized Locking Enabled] FROM sys.databases WHERE - [name] = DB_NAME(); -GO \ No newline at end of file + [name] = N'OptimizedLocking'; + +PRINT 'OptimizedLocking database created and configured successfully.'; \ No newline at end of file From 7a3e49aacfe2508492a01c15271c6f4c7f1153d1 Mon Sep 17 00:00:00 2001 From: Sergio Govoni Date: Mon, 8 Dec 2025 01:40:40 +0100 Subject: [PATCH 10/10] Enhance features README with Optimized Locking details and fix typo --- samples/features/readme.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/samples/features/readme.md b/samples/features/readme.md index 08d413ca52..6ed02dd3a4 100644 --- a/samples/features/readme.md +++ b/samples/features/readme.md @@ -8,6 +8,10 @@ In-Memory OLTP can significantly improve performance of transaction processing i Master Data Services (MDS) is the SQL Server solution for master data management. Master data management (MDM) enables you organization to discover and define non-transactional lists of data, and compile maintainable, reliable master lists. +[Optimized Locking](optimized-locking) + +Optimized Locking provides an improved transaction locking mechanism that reduces lock memory consumption and increases concurrency for workloads with high transaction volumes. Available in Azure SQL and SQL Server 2025 or higher, it uses Transaction ID (TID) locking and Lock After Qualification (LAQ) to minimize lock escalation and blocking. + [R Services](r-services) SQL Server R Services (in SQL Server 2016 and above) brings R processing close to the data, allowing more scalable and more efficient predictive analytics using R in-database. @@ -32,15 +36,8 @@ Graph tables enable you to add a non-relational capability to your database. The SQL Server Management Objects (SMO) Framework is a set of objects designed for programmatic management of Microsoft SQL Server and Microsoft Azure SQL Database. These code snippets demonstrate features of SMO and illustrate how to use SMO properties and collections without sacrificing performance. -[Optimized Locking](optimized-locking) - -Optimized Locking offers an improved transaction locking mechanism to reduce lock blocking and lock memory consumption for concurrent transactions. - ## Samples for Business Intelligence features within SQL Server [Reporting Services (SSRS)](reporting-services) -Reporting Services provides reporting capabilities for your organziation. Reporting Services can be integrated with SharePoint Server or used as a standalone service. - - - +Reporting Services provides reporting capabilities for your organization. Reporting Services can be integrated with SharePoint Server or used as a standalone service. \ No newline at end of file