A particularly nasty aspect of SQL UPDATE syntax is the predicate order, i.e. SET is before WHERE. So when you type it in order, there's a dangerous phase you have to go through if you hit enter by accident. Having run an `mkfs.ext3 /dev/sda` (note the missing partition number) by accident, I've learned to start potentially destructive commands by typing first whatever makes that command a comment (# in shell, -- in…
An UPDATE without a WHERE, or something close to it
21–30 of 112 posts
Re: An UPDATE without a WHERE, or something close to it
#22Re: An UPDATE without a WHERE, or something close to it
#23With databases, start a transaction first, then update, and look at the number of rows affected. If it's an oh shit moment, rollback, if not commit.
Re: An UPDATE without a WHERE, or something close to it
#24A particularly nasty aspect of SQL UPDATE syntax is the predicate order, i.e. SET is before WHERE. So when you type it in order, there's a dangerous phase you have to go through if you hit enter by accident. Having run an `mkfs.ext3 /dev/sda` (note the missing partition number) by accident, I've learned to start potentially destructive commands by typing first whatever makes that command a comment (# in shell, -- in…
I consider any SQL client that doesn't have implicit transactions as broken. Just too easy to make mistakes. However even with that, I agree with your second point. I always type -- commit in my SQL client and then highlight "commit" and execute only the highlighted text. That way I don't commit anything if I accidentally trigger the "execute all" action.
It was a long time ago, but I think it was with SQLPlus on Oracle - and presumably staging or something non-prod since it's not a particularly vivid memory!
Re: An UPDATE without a WHERE, or something close to it
#25Re: An UPDATE without a WHERE, or something close to it
#26A particularly nasty aspect of SQL UPDATE syntax is the predicate order, i.e. SET is before WHERE. So when you type it in order, there's a dangerous phase you have to go through if you hit enter by accident. Having run an `mkfs.ext3 /dev/sda` (note the missing partition number) by accident, I've learned to start potentially destructive commands by typing first whatever makes that command a comment (# in shell, -- in…
Otherwise, simply having a mindset of, I'm doing dangerous things also goes a long way.
Never do things if you are in a panicked/frantic state.
Edit: I guess running galera is actually a blessing. I can't run any write/update methods on our qa/prod data...
Re: An UPDATE without a WHERE, or something close to it
#27UPDATE also supports ORDER BY and LIMIT, which is kind of odd when you first see it.
Re: An UPDATE without a WHERE, or something close to it
#28If you put a small program/interface around SQL entry, you can trivially verify that a user entered a reasonable query before allowing to execute. I think validation that a query is going to do what you want is up to the user of the database, not the database vendor.
OK, this isn't about breaking an entire network but small details can be super helpful. I have only found a small number of companies who seem to care about error messages.
Re: An UPDATE without a WHERE, or something close to it
#29re: UPDATE without a WHERE In SSMS (the main query console tool thing for Sql Server) you can highlight a bit of code with the cursor (as if you want to copy/paste it) and press CTRL-E to execute it, its really handy when you've got a big sketchpad-like series of SELECT statements and you're doing exploratory tinkering. But if your UPDATE statement is accross three lines, its a little bit too easy to accidentally sel…
I haven't built one so I'm not complaining!
Re: An UPDATE without a WHERE, or something close to it
#30Waaay back in the .com boom days of the late 90s I was working at a place where the CTO did something like: UPDATE users SET password = '23r23r23rdsf'; Somehow he missed the "WHERE email = 'someone';" I forget exactly how many users had their password changed that day. For some reason (maybe MySQL didn't let you cancel an UPDATE like that way back in the old days?) to stop that query he ran into the other room and un…