12 pages
Snippets
Small copy/paste solutions with short explanations. Quick fixes and reusable code blocks, each labelled with the earliest SQL Server version it runs on.
My SQL Server
11 SQL Server snippets, each labelled with the earliest version it runs on.
- SQL Server 2008+
SQL Server: Bulk Update with JOIN
Update many rows from a supplied list of IDs + values using a temp table and JOIN. Ideal for data fixes.
- SQL Server 2016+
SQL Server: Convert Between XML and JSON
Turn XML into JSON with nodes() and FOR JSON, and JSON into XML with OPENJSON and FOR XML PATH, keeping nested rows nested.
- SQL Server 2008+
SQL Server: Find and Remove Duplicate Rows with ROW_NUMBER()
Preview duplicate rows, keep one per group, and delete the rest safely.
- SQL Server 2016+
SQL Server: Pass a List of IDs Without Dynamic SQL
Turn a comma-separated or JSON list into rows you can JOIN to, with no string concatenation or SQL injection risk.
- SQL Server 2008+
SQL Server: Query Large XML Documents Without Timeouts
Why shredding a big XML file with nodes() can take minutes, and the fixes that bring it back to seconds: no parent axis, full paths, text(), shredding once.
- SQL Server 2008+
SQL Server: Record Changed Rows with OUTPUT INTO
Capture before and after values of an UPDATE or DELETE in the same statement, so any data fix can be undone.
- SQL Server 2008+
SQL Server: Safe Bulk DELETE Using JOIN
Delete rows using a JOIN with a preview step to avoid accidental data loss.
- SQL Server 2008+
SQL Server: Turn XML Into Rows with nodes()
Shred an XML document into rows and typed columns with nodes() and value(), including child rows, attributes and namespaces.
- SQL Server 2008+
SQL Server: Update Only When Values Change
Avoid unnecessary writes and locking by updating rows only when values differ.
- SQL Server 2008+
SQL Server: Update or Delete Millions of Rows in Batches
Change large volumes of data in small batches to avoid table locks, log growth and blocking.
- SQL Server 2008+
SQL Server: UPSERT Without MERGE
Insert new rows and update existing rows safely without using MERGE.
-
TypeScript: Retry fetch with Exponential Backoff and Jitter
A small typed fetch wrapper that retries timeouts, rate limits and server errors without hammering the API.