4 ms·
The old "DELETE FROM some_table" <enter> Crap.. I meant "DELETE FROM some_table WHERE id=1" sighs
by enjo 14y ago
The old "DELETE FROM some_table" <enter>
Crap.. I meant "DELETE FROM some_table WHERE id=1"
sighs
- naudo 14y agoAfter doing that on a local db a couple of times, I started just writing the where clause first. Goes like this WHERE id = 1 ctrl + a DELETE FROM.... Found it's also helpful for writing SELECTS and avoiding the whole "oh crap, now let's load the entire DB" type of moments.
- iaskwhy 14y agoI always SELECT first and confirm I got the right result. Then I add the DELETE just before SELECT and commment out the SELECT line. Never fails!
- schrodinger 14y agoIf you're in a GUI where you can run only the highlighted code, I do this: select * -- delete from sometable where id = 1 Then you can run the whole thing to see what would be deleted, and highlight starting at the word delete to actually delete.
- methurston 14y agoI do this too, If I'm saving the file for reuse, I wrap the entire thing in /* */ when I'm done just in case I accidentally hit run script instead of run statement.
- vidarh 14y agoThe MySQL command line client has an argument "--i-am-a-dummy" that refuses to run UPDATE and DELETE's without a WHERE clause. More commands could use options to adjust how big guns they let you fire at your feet with...
- gknoy 14y agoSuch options might be more appealing to users if it were named something like "--extra-safety" or "--require-where".
- NSAID 14y agoHumorless users can use "--safe-updates" http://dev.mysql.com/doc/refman/5.0/en/mysql-tips.html#safe-updates http://dev.mysql.com/doc/refman/5.0/en/mysql-tips.html#safe-...
- sneak 14y ago...which is not the default. Fuck them.
- TrunkleBob 14y agoDo that once on a production system in the middle of a shipping run. Lesson learned. All my deletes written first as selects now, as a sibling comment suggested.
- ams6110 14y agoThat's what transactions are for. you realize the mistake, type ROLLBACK, and move on. Oh yeah, you're using a toy database aren't you.