Three results side by side. INSERT with OUTPUT shows the two new rows with SeedID 6 and 7. UPDATE with OUTPUT shows old and new Packets for four rows. DELETE with OUTPUT shows the two removed rows, Mint and Okra

Output Clause in Simple Examples: See the Rows You Just Changed

The OUTPUT clause shows the exact rows an INSERT, UPDATE or DELETE just changed, using the inserted and deleted tables. This post covers the output clause in simple examples with a small table of seed packets. It also shows how to save the rows with INTO, what error you get for the wrong table, and why triggers change the rules.

Read More
Gouache painting of a shelf of paired teacups with the extra twins gathered in a small red crate below

Delete Duplicate Rows in SQL Server and Keep One Copy

To delete duplicate rows in SQL Server and keep one copy, number the rows in each group with ROW_NUMBER and delete every row after the first. This post finds the duplicates first, previews the rows that will go, and deletes them inside a transaction while saving a copy of what was removed. It ends with a unique index on a cleaned column, so the same address can’t come back.

Read More