Skip to content

SQL Reference

HOLDLOCK

BEGIN TRANSACTION
SELECT * FROM Employees WITH (HOLDLOCK, ROWLOCK)
WHERE EmployeeID = 1
ROLLBACK TRANSACTION
EmployeeID | FirstName | LastName
-----------|-----------|---------
1 | John | Doe

The above SQL code starts a transaction and holds a lock on a specific row in the Employees table where the EmployeeID is 1. The lock holds until the transaction is complete. After selecting the desired data, the transaction is rolled back, releasing the lock.