Syntactically correct, but with disastrous consequences
Ever written something that passed syntax (and maybe even compiled), but that did something so far off from what you intended you can't imagine such a thing passed your fingers?
This morning, half-awake, I typed:
UPDATE invoice_item SET SKU = 'harl100' AND invoice_ID = 28448;
I meant for that "AND" to be "WHERE", so I was updating the one record associated with Invoice 28448. but... I hadn't had my coffee yet. MySQL raced off and did my bidding. When it replied, "4452 records updated", I damn near shit myself. I just set ALL the SKUs in the entire database to 'harl100'!
It's perfectly valid SQL, what I wrote. The AND clause is a syntactically correct no-op.
Fortunately, I'm keeping an association between invoice_item and PO_item. I was able to recover SKUs for all orders that have been processed and turned into purchase orders. That left about 100 records that my client is going to manually restore from order notification email he receives. He's pretty pissed, but glad I called immediately and had a solution that restored most of the data anyway.
Reminds me of a similar mistake I once meant where, typing too fast, I said:
UPDATE table SET field = 'newvalue' where ID + 1;
"ID + 1" tests true for ALL values of ID. Gulp.
|