Difficulty: Medium
Correct Answer: OPTIMISTIC
Explanation:
Introduction:
Optimistic concurrency aims to maximize concurrency by avoiding locks during reads and validating at write time that no conflicting change occurred. This model is common in high-read, lower-conflict workloads.
Given Data / Assumptions:
Concept / Approach:
In SQL Server cursors, OPTIMISTIC uses either a rowversion value or a checksum snapshot of columns to detect if a row changed since it was fetched. If it changed, the update is rejected at update time; otherwise, it proceeds. No update locks are taken during fetch, so readers do not block writers during enumeration.
Step-by-Step Solution:
1) Map options to semantics: OPTIMISTIC defers conflict detection, SCROLL_LOCKS locks early, READ_ONLY cannot modify, PESSIMISTIC is not a T-SQL cursor keyword.2) Select OPTIMISTIC as the model with no read-time locks.3) Note that OPTIMISTIC with checksum is a stricter variant but still optimistic.
Verification / Alternative check:
Check DECLARE CURSOR WITH OPTIMISTIC or OPTIMISTIC TYPE—behavior is to validate at UPDATE/DELETE time, not FETCH time.
Why Other Options Are Wrong:
Common Pitfalls:
Believing READ COMMITTED isolation equals optimistic cursor behavior; they are distinct concerns.
Final Answer:
OPTIMISTIC
Discussion & Comments