FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

10 snippets foundClear filters
SQL ServerBulk changes & set operations

Combine results while retaining duplicates

SQL Server: UNION ALL does not spend work removing equal rows.

SQL Server✓ Tested
SQL ServerBulk changes & set operations

Copy selected rows into another table

SQL Server: INSERT SELECT performs a set-based copy with an explicit destination column list.

SQL Server✓ Tested
SQL ServerBulk changes & set operations

Delete rows selected by a related table

SQL Server: A correlated EXISTS limits the delete to explicitly listed records.

SQL Server✓ Tested
SQL ServerBulk changes & set operations

Find rows in the first result but not the second

SQL Server: EXCEPT calculates a distinct result-set difference.

SQL Server✓ Tested
SQL ServerBulk changes & set operations

Find rows shared by two query results

SQL Server: INTERSECT compares complete selected rows and removes duplicates.

SQL Server✓ Tested
SQL ServerBulk changes & set operations

Increment a stored value in the database

SQL Server: An in-database arithmetic update avoids a separate application read-modify-write step.

SQL Server✓ Tested
SQL ServerBulk changes & set operations

Insert only keys absent from a destination

SQL Server: NOT EXISTS supports a set-based missing-row insert in a single-writer example.

SQL Server✓ Tested
SQL ServerBulk changes & set operations

Remove duplicate values while keeping the smallest key

SQL Server: Identify retained keys in a grouped subquery before deleting other copies.

SQL Server✓ Tested
SQL ServerBulk changes & set operations

Update rows selected by a related table

SQL Server: Use EXISTS to limit updates based on an independent eligibility table.

SQL Server✓ Tested
SQL ServerBulk changes & set operations

Update several classifications in one statement

SQL Server: A CASE expression computes the new value for each row covered by the update predicate.

SQL Server✓ Tested