Live data from Hacker News

I Accidentally Deleted All Our Data

taylor.fausak.me

11–20 of 78 posts

Re: I Accidentally Deleted All Our Data

#11
post #6

Although direct database update isn't recommended in SAP, still for some strange reasons it was needed in one of the projects to modify a wrong entry done by functional consultant. One of my fellow programmer was assigned this task and this is what she did - Update set = instead of Update set = where The code was executed on development server(thankfully) and it created a big mess. Full day work of 5 guys was lost. P…

[deleted]

Re: I Accidentally Deleted All Our Data

#12
post #3

I've done this a few times in my career. I'm smart enough now to always backup before I make any potential mistakes and test everything on a staging server. The worst was executing "DELETE FROM " instead of "DELETE FROM where userid='X' on a production server.

A buddy of mine showed me a cool trick to avoid this type of problem. What you do is first use SELECT to see the records in question:

   SELECT * from some_table where idx >= 5
Then, once you are staring at the records that came back (and are sure they are the ones you want to delete), change SELECT * to DELETE (and change nothing else) and rerun.

   DELETE from some_table where idx >= 5
Pretty hard to get it wrong with this approach ;-)

Re: I Accidentally Deleted All Our Data

#17
"We had a backup from earlier in the week"

week? That seems kind of off. I'd suggest setting up backups more often than that, especially for production data.

Sorry to hear about that. I destroyed a drive once a long time ago (~1994) as well. Happens to the best of us.

Re: I Accidentally Deleted All Our Data

#19
post #3

I've done this a few times in my career. I'm smart enough now to always backup before I make any potential mistakes and test everything on a staging server. The worst was executing "DELETE FROM " instead of "DELETE FROM where userid='X' on a production server.

If I were to re-imagine SQL I'd invert the sequence of the clause and statement for this very reason (FROM TABLE WHERE USERID="X" DELETE).

As it, when I'm writing sensitive SQL to fix an issue I end up writing the where clause first as a SELECT, then issue it.. check the results, history up, ctl-a and replace with a DELETE. Harrowing stuff.

Re: I Accidentally Deleted All Our Data

#20
post #3

I've done this a few times in my career. I'm smart enough now to always backup before I make any potential mistakes and test everything on a staging server. The worst was executing "DELETE FROM " instead of "DELETE FROM where userid='X' on a production server.

In situations where I can't avoid it (I've come into more projects with no development database and no concept of the idea than I'd like to say), I've taught myself that starting any data modification on a live server always begins with START TRANSACTION.
Post reply on HN