a↗agentbay.Get AgentBay
My account ▾
Menu
Back to results

t-sql-upserts-merge

Writes an upsert for Azure SQL Database that is still correct when two sessions run it at the same moment, and refuses the MERGE shapes that lose rows. Use when asked to "insert or update", "insert if not exists", "add or update", "make this insert idempotent", "upsert", "write a MERGE", "sync a staging table into the target table", make a…

Full publisher description

Writes an upsert for Azure SQL Database that is still correct when two sessions run it at the same moment, and refuses the MERGE shapes that lose rows. Use when asked to "insert or update", "insert if not exists", "add or update", "make this insert idempotent", "upsert", "write a MERGE", "sync a staging table into the target table", make a row-by-row load or import safe to run twice, or port ON CONFLICT DO UPDATE or ON DUPLICATE KEY UPDATE; and use when duplicate rows appear that nothing in the application created, or when error 2627, 2601, 8672, 10713 or a deadlock shows up under load. Covers why IF EXISTS then UPDATE ELSE INSERT is a race, what MERGE needs to be safe, which MERGE shapes to refuse outright, and the two patterns that are safe without MERGE. Key and index design belongs to design-azure-sql-schema, and general T-SQL dialect to t-sql-correctness.

Source details

Read SKILL.md ↗ · Browse skill folder ↗

microsoft/microsoft-sql

plugins/microsoft-sql-vscode/skills/t-sql-upserts-merge/SKILL.md

Pinned revision eeb1c6867c2d128763516a1aad41671c593cc189

Source checked

Reviewed licence: MIT
repository

Reviewed publisher revision ↗ · 2026-11-22

This skill page is available in English. Publisher instructions stay in their original language.