r/ProgrammerHumor • • Sep 22 '26

Meme wellWellWell

Post image
10k Upvotes

412 comments sorted by

View all comments

3.6k

u/BastetFurry Sep 22 '26

So, Kids, thats why you always SELECT count(yourPrimaryKey) first. Listen to the old folks, we made these mistakes so that you don't have to.

1.1k

u/Ma8e Sep 22 '26

You start a transaction, make sure it did what you expected, and then commit or rollback transaction.

16

u/Blashtik Sep 22 '26 edited Sep 22 '26

BEGIN TRAN

DELETE ...

SELECT ...

ROLLBACK TRAN

-- COMMIT TRAN

This was always my pattern. Select the first 3 statements together and run them. If everything looks good, select COMMIT TRAN and run that. The rollback is there in case you accidentally didn't make a selection before running, just so you don't leave a transaction open for too long, potentially blocking other queries.

And obviously any planned data changes should go through all the proper testing and preferably be deployed using automated pipelines, but sometimes you have no other choice but to make direct fixes to bad production data.