0

If I have a query that reads from a table, if that query is proceeded with the WAITFOR keyword (within the same batch and transaction) will the table lock of the preceding query be held until the WAITFOR completes and the transaction finishes? (I mean in the context of a Read Committed isolation level server.)

Example query:

BEGIN TRANSACTION

SELECT *
FROM ReallyLargeTable

WAITFOR DELAY '00:30';

COMMIT TRANSACTION

Does the WAITFOR DELAY cause the preceding query to hold its table lock against ReallyLargeTable for an additional 30 seconds until the delay is over and the transaction is committed?

1 Answer 1

4

It depends on the transaction isolation level.

In read committed it will release locks.
In "Repeatable read" and "Serializable" it will hold locks.

You can find more info in the following article: SET TRANSACTION ISOLATION LEVEL

2
  • Good point. In my case I mean in the context of the default isolation level on SQL Server, which I believe is Read Committed?.
    – J.D.
    Nov 14, 2019 at 22:48
  • 1
    Yes, Read Committed is default. Nov 14, 2019 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.