70-465 · Question #26
You have a database named DB1. You plan to create a stored procedure that will insert rows into three different tables. Each insert must use the same identifying value for each table, but the value…
The correct answer is A. Create a sequence object that holds the next value in the sequence. The scenario requires a shared, incrementing identifier across three tables that can also be reset - a sequence object is purpose-built for exactly this use case.
Question
Options
- ACreate a sequence object that holds the next value in the sequence.
- BCreate a sequence object that holds the next value in the sequence.
- CCreate a fourth table that holds the next value in the sequence.
- DCreate an identity column in each of the three tables.
How the community answered
(59 responses)- A78% (46)
- B12% (7)
- C7% (4)
- D3% (2)
Why each option
The scenario requires a shared, incrementing identifier across three tables that can also be reset - a sequence object is purpose-built for exactly this use case.
A SQL Server SEQUENCE object is an independent database object that generates numeric values in a defined order, incremented by a configurable amount, and can be reset to its starting value at any time using ALTER SEQUENCE with RESTART WITH. Because it exists independently of any table, a single sequence can supply the same value to multiple INSERT statements within one stored procedure invocation, satisfying the requirement for a shared identifier across all three tables.
Choice B is identical in wording to Choice A and is a duplicate option; A is selected as the canonical best answer, making B redundant rather than a distinct solution.
A fourth table could store the next value, but it introduces concurrency risks (e.g., dirty reads, update anomalies) and requires additional locking logic that a native SEQUENCE object handles automatically and more efficiently.
An IDENTITY column is scoped to a single table and auto-increments independently per table, so the three tables would generate different, unsynchronized values; additionally, IDENTITY values cannot be easily reset without truncating the table or using DBCC CHECKIDENT, making it unsuitable for a shared, resettable identifier.
Concept tested: SQL Server SEQUENCE object for shared incrementing values
Source: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-sequence-transact-sql
Topics
Community Discussion
No community discussion yet for this question.