Queries for READCOMMITTEDLOCK Table Hint
1. Usage of READCOMMITTEDLOCK table hint (to be used in transaction)
SQL Server Query 1
-- Window 1: Critical Audit Query - Forced to acquire shared locks
BEGIN TRANSACTION;
SELECT
OD.OrderID,
OD.ProductID,
OD.Quantity,
OD.UnitPrice
FROM [Order Details] AS OD WITH (READCOMMITTEDLOCK)
WHERE OD.OrderID = 10248; -- Select specific rows to observe blocking
ROLLBACK TRANSACTION
Create SQL query with SqlQueryBuilder 1
var (sql1, parameters1) = new SqlQueryBuilder()
.Select()
.Columns("OD.OrderID","OD.ProductID","OD.Quantity","OD.UnitPrice")
.From("[Order Details]","OD", new List<IHint>() { new READCOMMITTEDLOCK() })
.Where(new Where(new Column("OD.OrderID").Equale(10248)))
.Build();
Query build by SqlQueryBuilder 1
SELECT OD.OrderID, OD.ProductID, OD.Quantity, OD.UnitPrice FROM [Order Details] AS OD WITH (READCOMMITTEDLOCK) WHERE OD.OrderID = @pMAIN_2507200222035513410;
Parameters (If used)
Name | Value |
---|---|
@pMAIN_2507200222035513410 | 10248 |
Query Results 1:
OrderID | ProductID | Quantity | UnitPrice | |
---|---|---|---|---|
1 | 10248 | 11 | 12 | 14.0000 |
2 | 10248 | 42 | 10 | 9.8000 |
3 | 10248 | 72 | 5 | 34.8000 |