Hacker News new | ask | show | jobs
by raxxorrax 2477 days ago
I know how that feels. Even worse than any program or script, I especially dislike db management tools that just allow you to fire off random queries against the db. On the other hand you always get these little adrenaline rushes every time you do something like that until you can confirm that you actually fired that delete statement on the correct table... or not.
2 comments

The trick is to execute a BEGIN TRANSACTION, then do whatever you need to, then verify that you've done everything correctly (consider doing this twice). Then, only when you're absolutely certain all is as it should be, do you execute a COMMIT TRANSACTION.

All of this is predicated on the idea that you know exactly what changes you need to make, exactly what state the database should be in afterwards, exactly how to verify this, and also how to check for unintended side-effects.

I suppose the real trick is to avoid having to do this kind of thing in the first place but, as well all know, sometimes that's just not possible.

Oh dear, I know that feeling. It's just a few rows and you've done it a hundred times before. You type in the delete query in a rush and look at it for a minute.. Just to make sure... Well OK: You hit F5 and then it runs... and runs... and runs...

(12'503'450 rows affected)

Oh crap.