Cursor Locking

On Day 12, "Understanding Database Locking," you learned all about how SQL Server uses locks to prevent accidental changes to the database. When you use cursors, the SELECT statement in the cursor DECLARE is subject to the same transaction-locking rules that you have seen applied to other SELECT statements in Day 12. In cursors, however, you can acquire an additional set of scroll locks based on the cursor concurrency level.

As a review, the transaction locks that are used by any SELECT statement, including those in a cursor definition, are controlled by

  • The transaction isolation level setting for the connection

  • Any locking hints specified in the FROM clause

These locks are maintained until the end of the current transaction for ...

Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.