Database cursors and concurrency visibility Which cursor type shows changes of any kind and from any source as they occur (i.e., the application always sees the latest committed state)?

Difficulty: Easy

Correct Answer: Dynamic cursor.

Explanation:


Introduction / Context:
In relational databases, a cursor defines how an application scans a result set and what changes it can “see” while it is open. Understanding the visibility guarantees of each cursor type is essential for writing correct, concurrent applications that avoid stale views of data or surprising anomalies.


Given Data / Assumptions:

  • We are comparing common server-side cursor models: forward-only, static, keyset, and dynamic.
  • Other sessions may insert, update, or delete rows while a cursor is open.
  • We care about whether the cursor reflects those committed changes.


Concept / Approach:

A dynamic cursor is defined so that it reflects the current, committed state of the underlying tables. By contrast, a static cursor is a snapshot taken when the cursor opens, a keyset cursor has a fixed key list with values refreshed for those keys, and a forward-only cursor is a simple streaming cursor with limited navigation and implementation-dependent visibility. The question asks which cursor shows any type of committed change from any source while it is open—this is precisely the property of a dynamic cursor.


Step-by-Step Solution:

1) Identify cursor types and their visibility properties.2) Static cursor: data does not change from the application's perspective after open.3) Keyset cursor: set of keys (rows) is fixed, but values for those keys can change; inserts that introduce new keys are not visible.4) Forward-only cursor: minimal navigation; visibility varies but typically not fully dynamic.5) Dynamic cursor: reflects inserts, updates, and deletes from any session as they become committed.6) Therefore, the correct choice is the dynamic cursor.


Verification / Alternative check:

Vendor documentation (e.g., SQL Server's cursor types) describes dynamic cursors as showing all committed changes, confirming our reasoning independent of implementation details.


Why Other Options Are Wrong:

  • Forward-only cursor: navigation property, not a visibility guarantee; typically not fully dynamic.
  • Static cursor: materialized snapshot, so no visibility to new inserts or deletes.
  • Keyset cursor: does not see rows outside the fixed key list; partial visibility only.
  • Read-only snapshot cursor: a distractor that implies static behavior, not dynamic.


Common Pitfalls:

  • Confusing navigation (forward-only) with concurrency visibility.
  • Assuming keyset cursors see new rows; they do not—only existing keys refresh.
  • Believing static cursors update themselves; they are intentionally stable.


Final Answer:

Dynamic cursor.

More Questions from Managing Multiuser Databases

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion