HOLDLOCK
Example
Section titled “Example”BEGIN TRANSACTIONSELECT * FROM Employees WITH (HOLDLOCK, ROWLOCK)WHERE EmployeeID = 1ROLLBACK TRANSACTIONOutput
Section titled “Output”EmployeeID | FirstName | LastName-----------|-----------|---------1 | John | DoeExplanation
Section titled “Explanation”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.