by rick888 · 15y ago · 0 comments
The worst was executing "DELETE FROM <table>" instead of "DELETE FROM <table> where userid='X' on a production server.
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 ;-)I realized what I did the instant I hit enter, and all the blood drained from my face.
Thank god for backups.
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.