Question 160
A web service inserts a transaction and then performs a nontransactional SELECT MAX(Id) that sometimes returns another user's row. What should a technical reviewer verify before approving completion?
Explanation
Correct Answer
MAX(Id) is unsafe for concurrent identity retrieval; OUTPUT ties returned keys to the statement. The observation “Concurrent calls each receive the identifier from their own insert” directly confirms the chosen action worked for this situation: A web service inserts a transaction and then performs a nontransactional SELECT MAX(Id) that sometimes returns another user's row.
Incorrect Answers
Suppressing SQL errors conceals failed transactions; THROW propagates a meaningful failure. This observation would not establish that the required result occurred for A web service inserts a transaction and then performs a nontransactional SELECT MAX(Id) that sometimes returns another user's row. The confirming test is: Concurrent calls each receive the identifier from their own insert.
A scalar function encapsulates a single-result expression, not a full transaction workflow. This observation would not establish that the required result occurred for A web service inserts a transaction and then performs a nontransactional SELECT MAX(Id) that sometimes returns another user's row. The confirming test is: Concurrent calls each receive the identifier from their own insert.
RANK leaves gaps after ties while DENSE_RANK does not. This observation would not establish that the required result occurred for A web service inserts a transaction and then performs a nontransactional SELECT MAX(Id) that sometimes returns another user's row. The confirming test is: Concurrent calls each receive the identifier from their own insert.