t-sql-upserts-merge

Installation
SKILL.md

Write an upsert that survives concurrency, and refuse the dangerous MERGE

An upsert looks like a one-statement problem and is a concurrency problem. Both of the shapes a model reaches for first, IF EXISTS ... UPDATE ELSE INSERT and a bare MERGE, are races. They pass every single-session test and fail the first time two callers arrive together.

Measured on 2026-08-28 against a live engine reporting EngineEdition 5 and Edition SQL Azure. Open the measured runs when a number below is disputed, or before changing one.

What the race actually costs

Eight sessions, twenty increments each, one hot key. A correct upsert ends at 160.

Installs
10
GitHub Stars
23
First Seen
Sep 28, 2026