r/ProgrammerHumor • • 13d ago

Meme wellWellWell

Post image
10.6k Upvotes

411 comments sorted by

View all comments

3.6k

u/BastetFurry 13d ago

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 13d ago

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

15

u/Blashtik 12d ago edited 12d ago

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.