• Matt (unregistered) in reply to Benny
    Benny:
    rm -rf /etc /some/folder/I/want/to/trash...

    Notice the space after etc.

    rm -rf is dangerous.

    I type "rm -rf" all the time, and as a Linux sysadmin, it always makes me twitch. What's scary is how fast I can type those exact chars in the blink of any eye, from typing them so often.

  • Matt (unregistered) in reply to brazzy
    brazzy:
    Fortunately, being admin actually didn't mean all that much in this system. The worst thing you could do with it would have been to remove overdraft checking and allow people to buy more stocks than they have money for.

    Not so trivial. That's how the Great Depression started.
    :)

  • Just Some Guy (unregistered) in reply to DWalker59
    DWalker59:
    Delete without a WHERE clause ... whenever I type "Delete From Table" I always, immediately, type "Where" on THE SAME LINE.

    I always start the line with "-- DELETE", type the rest of the line, CTRL-A to go back to the beginning, delete the comment marker, then run it.

  • (cs)

    I just pulled a good one the other day. We had a server sitting idle that a cow-orker and I had wiped and installed ESXi on, and renamed SUPERNOVA. It had no network cables running to it, so I put in a datacenter ticket to have them run and have the server relabeled from FOOBAR1 to SUPERNOVA. Came in the next day to an e-mail from the ex-Marine DC manager: "I ran the cables but there's no link light, I think your server's not configured like you think it is."

    I confirmed with the network guys that the switch ports were active, then I went down to the datacenter to have a look. As soon as I stepped in front of the rack I realized my mistake: the server we reformatted was FOOBAR2, not FOOBAR1. Fortunately FOOBAR1 was an idle, powered-off server that we had scavenged parts from (which is why its name was in my head), so it wasn't a live production box or anything, but it could easily have been.

    I sent a mea culpa e-mail and took my well-deserved razzing from the DC manager.

  • Mark Tempel (unregistered) in reply to OzPeter
    OzPeter:
    Your assuming that industrial controllers are programmed via a source->compiler->executable system. ProTip .. They're not.
    When I did embedded code for a microcontroller, I used a C-Compiler from Kiel. They had support for many controllers (mine was an 8051). I also used #ifdef DEBUG to disable watchdog timers in debug mode.

    I'm not sure if there are any tools that have this kind of support for the controller you use, but I feel like I have to add the following ;-) <snark> ProTip use a development environment that gives you the tools you need. </snark>

  • Azeroth (unregistered)

    Back before I happily earned my living with programming I worked at PC hardware shop during college. It was when most people had already upgraded from Windows 3.1 to Windows 95. A customer brought us a PC with Windows 3.1 which had some kind of a problem that I don't remember. Relying only on my experience in school's computer class I decided to simply reinstall. I have rarely seen anyone as angry as my manager was after he found out. It turns out that people tend to, you know, keep stuff on their computers that they don't want to lose, but that was the least of the problems. Back in those days you got drivers on floppies and those floppies were usually lost and drivers hard to replace. So in the end there was a freshly installed PC without files and with devices not working for the customer to enjoy.

  • Keybounce (unregistered) in reply to Benny
    Benny:
    rm -rf /etc /some/folder/I/want/to/trash...

    Notice the space after etc.

    rm -rf is dangerous.

    "You told me to type rm star dot o, and it came back with dot o not found."

    rm * .o versus rm *.o

    Maybe there's a reason most modern build scripts put the .o files in a different directory than the source files.

  • Jon B (unregistered)

    I have two nits to pick on the second story. First, not giving a food pellet is not negative reinforcement. Negative reinforcement is when you punish the wrong behavior (like shocking the poor critter). Second, one of the few things I remember from being a psych minor is that inconsistent positive reinforcement is more effective than consistent reinforcement. Meaning it's better to only sometimes give out the food pellet.

    So it's a feature, not a bug!

  • Kevin (unregistered)

    I once deleted all of the images from my office's product database. (Due to the magic of Windows 2000 symlinks, I thought I was cleaning up an unnecessary extra copy.) Fortunately, the IT manager had arbitrarily decided that the night before was a good time to randomly back everything up for the first time in six months.

    Related, at my current office, we lost 2 disks of our raid array simultaneously, then discovered that our automated system had been backing up a symlink to our precious files, rather than the precious files themselves.

  • (cs) in reply to Wonkothesane
    Wonkothesane:
    campkev:
    I've got a good one. Was writing code for a web banking application. One friday afternoon, we put out a new version of our app that introduced a few minor features, nothing big. We ran the update to the database and posted the code. Logged in, did a basic check to make sure it didn't blow up and went home for the weekend.

    What? Deploy on a friday and go home? Are you an f'ing moron? I wouldnt expect that for a trivial system which would hardly be used over the weekend, but a banking app? Actually... I dont believe you.

    Wasn't my decision to deploy on a Friday afternoon. I was the most junior programmer on the team at the time. And the policy got changed after that. I think Wednesday before noon was the only allowed time.

  • (cs) in reply to Jon B
    Jon B:
    I have two nits to pick on the second story. First, not giving a food pellet is not negative reinforcement.

    The article never says "negative reinforcement"; it just says "negative feedback", which, AFAIK, doesn't have a specific psychological meaning.

    Negative reinforcement is when you punish the wrong behavior (like shocking the poor critter).

    No it isn't. That's called punishment. (Specifically, the addition of a negative consequence to undesirable behavior is punishment.)

    Negative reinforcement is the removal of something bad as a response to correct behavior.

    (From wikipedia: "Turning off (or removing) an annoying song when a child asks their parent is an example of negative reinforcement (if this results in an increase in asking behavior of the child in the future). Another example is if a mouse presses a button to avoid shock. Do not confuse this concept with punishment.")

    And you were a psych minor? This is like psych 101 stuff, albeit psych 101 stuff that is commonly misunderstood.

  • (cs) in reply to Mark Tempel
    Mark Tempel:
    When I did embedded code for a microcontroller
    Industrial controller/PLC/Motion controller != embedded controller

    < start general rant :D >

    Mark Tempel:
    ProTip use a development environment that gives you the tools you need.
    Why do you people seem to insist that the problem is just not selecting the correct tool and that I have a choice when developing industrial solutions.

    The only choice I have is to not work in the field. There is no choice of tools. At the control systems level it is all vendor driven, proprietary and tied to the hardware. Microsoft would give its virtual left nut to have the sort of lock-in that occurs in industry.

    Yes the major players all implement IEC 61131-3, but that doesn't mean jack. You can't just up and replace one brand of PLC with another like you can replace an HP server with a Dell server. So you are stuck with a vendor and stuck with the tools that a vendor will provide. < / end general rant>

  • lawl (unregistered)

    dont know if this was said yet, but i always end my delete queries with 'limit 1' just incase

  • iToad (unregistered)

    The PLC equivalent to #ifdef or #debug is using a programming tool to force boolean bit values (or external I/O bit values) to True or False. Sometimes, these bits control the operation of huge, expensive pieces of machinery.

    The PLC equivalent of leaving the debug code in, is forgetting to unforce the bits. With some programming products this is real easy to do.

  • Wolfraider (unregistered)

    My big oops. Back in the Windows 2000 Active Directory days, there was a bug that the sysvol share did not replicate properly. The fix from Microsoft was to backup the sysvol share, delete a folder from every domain controller and then copy the folder back to one domain controller and replicate. Once I deleted the folder from one domain controller without backing up the sysvol share. I immediately noticed my mistake and check the other domain controllers but no folders where found. Right when I deleted the folder, the domain synced. I basically replicated death and wiped out the whole Active Directory structure in the matter of minutes. Needless to say, we didn't have any backups and I spent a couple days running scripts to rebuild AD.

  • Warsteiner (unregistered)

    I have a "rm -rf" one as well.

    I was deploying something on a production server. An ant script was used to do this. I had edited a variable in the ant script to point at current user's home directory, "~/whatever", where some files were to be copied.

    The ant script didn't seem to work. After wondering why, I noticed ant had created a subdirectory "~" instead of referring to the home directory. And before I even noticed, I had typed "rm -rf ~".

  • JayC (unregistered) in reply to Matt

    begin transaction delete from table -- oh noes! rollback transaction -- whew!

    I've done that numerous times.... just gotta make sure you're not locking down some important table with the transaction.

  • JayC (unregistered) in reply to JayC

    by "that" I ONLY mean't using the "begin transaction" trick, BTW I also have used the appending a where clause.

  • Bill W (unregistered)

    Back circa 1995, when a Unix server was no longer required for its job of verifying accounts, handling print queues emails and all the other things that take 5 windows boxes to do, it often got demoted to a low impact application server.

    One of these was handed to us, but it was low on free space, and I noticed it hadn't been properly wiped. So I decided to clear out financial and purchasing records, which was when I realised I wasn't telnetted onto that box, but was on the new main box.

    Si I did a restore, did a CHOWN to put the ownership back as it should, changed the permission back.

    It didn't quite work, but I covered up my tracks enough that the central sysadmin couldn't figure out who had f***ed up and I learned not to do that again

  • Me (unregistered) in reply to DWalker59
    DWalker59:
    Delete without a WHERE clause ... whenever I type "Delete From Table" I always, immediately, type "Where" on THE SAME LINE. Even if I stop to think about what the Where clause should say, I make sure it's entered right away, on the same line. That minimizes the possibility that a slip of the hand or some forgetfulness will do something to execute the whole line. (I have, a couple of times, executed the line "Delete From Table Where", but thankfully, that's a syntax error instead of a "Whoops" moment.)

    Usually, I type "Select * From Table Where ..." and then, when it looks right, I change "Select *" to "Delete".

    Of course, these aren't new techniques, but they are useful.

    Yup, I do the select first to make sure it's the right entry, and then change to a delete....

    I've had 2 big cock-ups, both caused by executing shell commands with super user priviliges.

    The first was a series of commands that included a mv (something like mkdir tmp; for FILE in find .; do mv ${FILE} tmp/${FILE}; done. ) As it wasn't working with my permissions, i changed to superuser, forgetting that with the change of account, I was suddenly in the root directory. All of sudden, the error "command not found" started to come up (and pretty soon end users were ringing to ask why they were having a whole host of issues logging in)... Doing things as root is never a good thing, nor is using relative paths, nor is not echoing output as we go....

    Second f-up, was as (non-root) but user with ownership of most of our applications file. I was retrieving logs that are tarred with their absolute path prefixed by . (period) , so that when they are untarred, they hold their original directory structure below the current directory. When deleting these logs, I forgot to use the ., and instead started to remove entire directories in the original path....Things very quickly went pear shaped.... lesson: Use Absolute, Absolute paths, avoid super users when possible, and, mos importantly THINK

  • MetaMan (unregistered)

    Just ask yourself, what would Jessica Simpson and Megan Fox do in a situation like this?

  • Buzzard (unregistered)

    I have a bank related nightmare too. I worked on an app that processed large value wholesale currency transfers. These transfers entered out system and were processed straight away, that is, unless they were future dated.

    In this case, they were saved to a database.
    Every morning a process started up to detect if there were any future dated transactions that were due for payment today and if there were it sent them off to the payments system for processing.

    Well, day one, the system goes online for the first time and everyone was amazed that all our hard work had paid off. The system churned through about 1 Billion dollars worth of transactions and despite a few memory leaks and server restarts, everything worked perfectly.

    Day two was pretty much the same as day 1, all good.

    Day three, the sh1t hits the fan.... The process that looks for and pays any future dated transactions starts and processes not only todays payments, but also those that had been paid yesterday. I had forgot to update the paid status of those future dated payments, that had already been processed the day before.

    What resulted was a really shitty day, $6 million had been over paid and my only comeback was 'it should have been tested'. Anyway, eventually we got the money back, but lost $50K on interest. My boss was pretty good about the whole mess, and apparently there was money in our budget for such a problem.

    It didn't stop me from going to the pub, buying and smoking a whole pack of ciggies ( and forgetting to remove my nicotine patch ) that night.

  • Duke of New York (unregistered) in reply to iToad
    iToad:
    The PLC equivalent to #ifdef or #debug is using a programming tool to force boolean bit values (or external I/O bit values) to True or False. Sometimes, these bits control the operation of huge, expensive pieces of machinery.

    The PLC equivalent of leaving the debug code in, is forgetting to unforce the bits. With some programming products this is real easy to do.

    Usually in a situation like this, what you need is a jumper rather than a coded bit
  • Dazzer (unregistered)

    Wanted to add my own OOPS.

    Forming a URL query string, and somewhere I forgot to put in a ampersand. >.<

  • Fortrinn (unregistered)

    Mine was on our Sharepoint servers... which were still waiting to get a staging and live environment, so we were editing on live.

    For those of you familiar with Sharepoint, the 'Delete this site' feature is dangerous, and something that IMO really shouldnt be on the web front end.

    Especially when you forget to check the URL of the site you think you are deleting, and instead, destroy the whole site collection.

  • Gary Olson (unregistered) in reply to SomeWebDude
    the contact email address they had on file was the email address of my predecessor.
    The same thing happened with the Verisign certificates for all our main systems...I have never seen a PO written so quickly.
  • Anonymous Coward (unregistered) in reply to Jon B
    Jon B:
    I have two nits to pick on the second story. First, not giving a food pellet is not negative reinforcement. Negative reinforcement is when you punish the wrong behavior (like shocking the poor critter). Second, one of the few things I remember from being a psych minor is that inconsistent positive reinforcement is more effective than consistent reinforcement. Meaning it's better to only sometimes give out the food pellet.

    So it's a feature, not a bug!

    I read the same thing. The cliche'd Pavlovian response that everyone hears about isn't the most effective situation. You want to only SOMETIMES reward the desired behavior. I'll leave it to the psych majors to explain that one.

  • Anonymous Coward (unregistered) in reply to OzPeter
    OzPeter:
    Mark Tempel:
    When I did embedded code for a microcontroller
    Industrial controller/PLC/Motion controller != embedded controller

    < start general rant :D >

    Mark Tempel:
    ProTip use a development environment that gives you the tools you need.
    Why do you people seem to insist that the problem is just not selecting the correct tool and that I have a choice when developing industrial solutions.

    The only choice I have is to not work in the field. There is no choice of tools. At the control systems level it is all vendor driven, proprietary and tied to the hardware. Microsoft would give its virtual left nut to have the sort of lock-in that occurs in industry.

    Yes the major players all implement IEC 61131-3, but that doesn't mean jack. You can't just up and replace one brand of PLC with another like you can replace an HP server with a Dell server. So you are stuck with a vendor and stuck with the tools that a vendor will provide. < / end general rant>

    Is this your first day on this site?

    It's filled with naive, idealistic kids who think "WTF? Just change the toolset, environment, platform, vendor agreements, SLAs, policies and procedures, and get on with it."

    To those of you that fall into that category, please wait until you've spent some time working for big companies. Or until you have a mature system that can't be easily re-written because of dependencies or other reasons. Oftentimes, you can't just say to your boss "The real WTF is this Java shenanigans. Who cares if it's business critical. Just throw out the entire system that hundreds of thousands of man hours and millions of dollars was spent building. I'll re-do it in .NET! And I know I'll do it right because I'll use the tools that I prefer; which is what matters..."

  • Bow chka bow wow (unregistered) in reply to MetaMan

    Probably lean forward over a desk, slowly.

  • Nick (unregistered)

    I created a robocopy batch file to mirror a directory from a primary domain controller to a backup server. My script set the working directory using an administrative share, then ran the robocopy command using the current working directory as the destination.

    This all worked fine in testing, so I set it as a scheduled job in Windows under our scheduled tasks user and gave it another test run, unfortunately the scheduled tasks user cannot access administrative shares so the command to set the working directory failed leaving it as the windows 2000 default: C:\

    The robocopy command ran and since it was a mirror, it proceeded to delete all files from C:\ on the PDC, I went to check the log and saw it deleting everything and cancelled the job, but not before it had deleted half the files from the server.

    Restored from a backup, but didn't realise that Backup Exec stores the Windows boot files in System State and not in C:\ so when the server came back up after the restore I got the dreaded "NTOSKRNL.EXE is missing or corrupt", by this time it was 8:00 PM, so I went home (09:00-17:00 support service). I spent that night making a boot CD and had the server back up by 9:30 the next morning.

    Needless to say, I now triple check all my robocopy scripts.

  • Subroutine (unregistered) in reply to Just Some Guy
    Just Some Guy:
    DWalker59:
    Delete without a WHERE clause ... whenever I type "Delete From Table" I always, immediately, type "Where" on THE SAME LINE.

    I always start the line with "-- DELETE", type the rest of the line, CTRL-A to go back to the beginning, delete the comment marker, then run it.

    I start by typing the WHERE clause, then move to the beginning and fill in the UPDATE/DELETE...

  • (cs) in reply to Kevin
    Kevin:
    I once deleted all of the images from my office's product database. (Due to the magic of Windows 2000 symlinks, I thought I was cleaning up an unnecessary extra copy.)
    A colleague of mine once did something very similar - he didn't realise that deleting all the product records out of the database view he was using would also delete them from the underlying product table. Cue a rather frantic morning for half of the IT department and a number of upset remote users.
  • twatter (unregistered) in reply to pitchingchris
    Not Whoops. Lawsuit !

    Yes.. They help.... (lawsuits do not fix problems).

  • Ed M (unregistered)

    Google for "always mount a scratch monkey" for really classic WTFs in this vein.

  • AshG (unregistered)

    I think SQL is a total screw-up as a language. I managed to delete 3000 customer records by the same mistake.

    I think someone should redesign the language so that every statement starts with WHERE.

    Besides, WTF with "IS [NOT] NULL" as opposed to "[!]=NULL"? How many wasted lines of code does this generate? Why is it a big difference if the value is null and we can't use a generic binary comparison operator on it?

  • Tim williscroft (unregistered)

    One idea my old boss had which I think people can learn from. (This is not a joke)

    Disable the watchdog during testing.

    If it fails: find the bugs in the code and fix them.

    Don't use the watchdog to recover from bugs in the code. Use it to recover from "gravity has failed" kinds of faults. Like when the CPU locks up, network controller freezes the bus etc.

    After testing, (there are no bugs for a week/month/etc of testing ) THEN enable the watchdog.

    Your mileage will not vary significantly. Should your boss not be interested in this kind of reliability, get it in writing. Then the next time a $1.5M system breaks, you keep your job.

  • SpamBot (unregistered) in reply to M
    M:
    The one bright point of the episode was that the onsite project manager, at the end of the day, commented "just think of it this way... for the rest of your life, no matter what happens in your career, you'll always be able to say to yourself, 'at least it's not as bad as that one day at Madison Square Garden.'"

    So far, he's been right.

    What a nice bloke! Makes a change on this site!

  • Level 2 (unregistered) in reply to brazzy
    brazzy:
    Fortunately, being admin actually didn't mean all that much in this system. The worst thing you could do with it would have been to remove overdraft checking and allow people to buy more stocks than they have money for.

    At last we have found the cause of the banking crisis!

  • Level 2 (unregistered) in reply to jimlangrunner
    jimlangrunner:
    DiverKas:
    DWalker59:
    Delete without a WHERE clause ... whenever I type "Delete From Table" I always, immediately, type "Where" on THE SAME LINE. Even if I stop to think about what the Where clause should say, I make sure it's entered right away, on the same line. That minimizes the possibility that a slip of the hand or some forgetfulness will do something to execute the whole line. (I have, a couple of times, executed the line "Delete From Table Where", but thankfully, that's a syntax error instead of a "Whoops" moment.)

    Usually, I type "Select * From Table Where ..." and then, when it looks right, I change "Select *" to "Delete".

    Of course, these aren't new techniques, but they are useful.

    Wrapping it in a transaction and handling it properly would be the right way to do it. Laziness HAS to be 99% of the cause of most problems.

    Or ignorance (lack of education in the matter). He may simply not yet know that you can do such things. ALLOWING someone to work on such a system without proper education is a WTF in itself, but it happens with alarming regularity.

    I myself am learning these things. In the meantime, "SELECT" lets me narrow my queries to the correct scope before changing to DELETE, which is just a darned good idea.

    He could be using MySQL with the myisam engine. No transactions supported.

  • (cs)

    I am in Thailand. We are an agricultural company. In the springtime we buy from farmers. The operator types in the farmer code and then operates the program to put in bale weight and quality. It creates records and pay slips.

    One winter I modified the program so it has a list of the farmers codes and names. When you type in the code, it shows you the name, and prints the name on the pay slips. I tested it extensively, many times, and it always worked. Code goes in, name comes up.

    The first day of actual buying: hundreds of farmers are there to see how much we're paying; top management is there to make speeches. Finally we start. First farmer comes up, the operator types in his code number. Up pops his name. Operator says (in Thai), "That's not him!" Oops.

    After two seconds of thought I knew what caused the bug. I asked them to wait an hour. Fortunately I had my notebook computer with me, and in that hour I was able to find and fix the bug and give them a new version of the program. Then all went well.

    The bug was that in my farmer code hash table I had a modulo that was too small. Short test lists of farmers did not hit the modulo. On tests of long lists of farmers, a Thai name came up and I had no idea whether it was the right name. Hey, I got a name, right?

    So that's the phrase that keeps me awake at night: "That's not him!"

  • (cs) in reply to AshG
    AshG:
    I think SQL is a total screw-up as a language. I managed to delete 3000 customer records by the same mistake.

    I think someone should redesign the language so that every statement starts with WHERE.

    Besides, WTF with "IS [NOT] NULL" as opposed to "[!]=NULL"? How many wasted lines of code does this generate? Why is it a big difference if the value is null and we can't use a generic binary comparison operator on it?

    The logic is that using any binary operators on a null (including comparison!) returns null.

  • Fowl (unregistered)

    At one point, after having downloaded the Windows Beta, not wanting to waste a consumable (blank DVD) "USB install" I think.

    Following some randomly pulled up guide from google I get to the part where you repartiton the flash drive and mark it as bootable.

    diskpart list disk

    Disk ### Status Size Free Dyn Gpt


    Disk 0 Online 298 GB 0 B Disk 1 Online 298 GB 511 MB Disk 2 Online 4 GB 0 B

    clean

    "Hmm.. why is this taking so long... and why is my hard drive light flashing"

    The operation completed successfully.

    I get a balloon from µTorrent telling me it can't find a file. Then another one. And another. My music stops playing. My email client crashes. Process Explorer goes away. My desktop goes blank.

    "Oh. Oh Shit!"

    ...

    Note to self: just because it has a number in megabytes doesn't mean it's not a hard drive.

    ...

    After some frantic googling, I find a program called "TestDisk". Press a few buttons, it recreate partition table.

    Everything is right in the world.

    I still don't have any backups. Oh well, it's my box I'm screwing =P

  • Peter (unregistered)
    Alex:
    I figured today'd be the perfect day to rehash "//TODO: Uncomment Later", originally pulished on March 14th, 2007.
    //TODO: correct the spelling of "published"
  • Anonymous (unregistered)

    I've been at my current company for several years now and have had no major production failures. Unfortunately, this is at least in part due to the fact that we've never managed to sell our product to anyone.

  • Aaron (unregistered) in reply to OzPeter

    That doesn't stop you from running m4 (or even gcc -E) over your sources before you feed them to the embedded tool.

    Complaining about an environment that only takes source code for input and doesn't provide a macro language is just kind of silly given all the macro processors available.

  • (cs) in reply to Fowl
    Fowl:
    Oh well, it's my box I'm screwing =P

    That sounds like quite a feat.

  • (cs) in reply to AndyCanfield
    AndyCanfield:
    I am in Thailand. We are an agricultural company. In the springtime we buy from farmers. The operator types in the farmer code and then operates the program to put in bale weight and quality. It creates records and pay slips.

    One winter I modified the program so it has a list of the farmers codes and names. When you type in the code, it shows you the name, and prints the name on the pay slips. I tested it extensively, many times, and it always worked. Code goes in, name comes up.

    The first day of actual buying: hundreds of farmers are there to see how much we're paying; top management is there to make speeches. Finally we start. First farmer comes up, the operator types in his code number. Up pops his name. Operator says (in Thai), "That's not him!" Oops.

    After two seconds of thought I knew what caused the bug. I asked them to wait an hour. Fortunately I had my notebook computer with me, and in that hour I was able to find and fix the bug and give them a new version of the program. Then all went well.

    The bug was that in my farmer code hash table I had a modulo that was too small. Short test lists of farmers did not hit the modulo. On tests of long lists of farmers, a Thai name came up and I had no idea whether it was the right name. Hey, I got a name, right?

    So that's the phrase that keeps me awake at night: "That's not him!"

    Yeah, that *almost never* happens to me.

    How do you say "That's not him!" in Thai?

  • (cs) in reply to Some Wonk
    Some Wonk:
    Matt:

    What does the atomicity of a transaction have to do with it? He runs the SELECT first, so he can ensure that it includes the right records. Then he changes "select *" to "delete".

    Are you talking about wrapping a single delete in a transaction? That makes no sense.

    you make it an explicit transaction, so you have time to decide whether you want to commit or roll back, when you see 3,000,000 rows affected, rather than 1 row affected, as you thought you should.

    You're still better off testing your where clause with select first. Even if it only deletes one row, are you sure it deleted the right one row?

  • (cs) in reply to Some Wonk
    Some Wonk:
    Matt:
    DiverKas:
    DWalker59:
    Delete without a WHERE clause ... whenever I type "Delete From Table" I always, immediately, type "Where" on THE SAME LINE. Even if I stop to think about what the Where clause should say, I make sure it's entered right away, on the same line. That minimizes the possibility that a slip of the hand or some forgetfulness will do something to execute the whole line. (I have, a couple of times, executed the line "Delete From Table Where", but thankfully, that's a syntax error instead of a "Whoops" moment.)

    Usually, I type "Select * From Table Where ..." and then, when it looks right, I change "Select *" to "Delete".

    Of course, these aren't new techniques, but they are useful.

    Wrapping it in a transaction and handling it properly would be the right way to do it. Laziness HAS to be 99% of the cause of most problems.

    What does the atomicity of a transaction have to do with it? He runs the SELECT first, so he can ensure that it includes the right records. Then he changes "select *" to "delete".

    Are you talking about wrapping a single delete in a transaction? That makes no sense.

    you make it an explicit transaction, so you have time to decide whether you want to commit or roll back, when you see 3,000,000 rows affected, rather than 1 row affected, as you thought you should.

    using SELECT * first still have it's uses though. If I was expecting around 50 lines and see 60 or 65 it's nice to know what it went correctly and I didn't accidently include a couple extra lines

  • Anonymous Coward (unregistered) in reply to Subroutine

    Yeah, I normally used to write my where, then my delete. I'd start with "where userid=40;" and then I add "update users set password=sha1('whatever')" before that. Then one day I hit the semicolon by instinct just before enter.

    update users set password=sha1('whatever'); where userid=40;

    ERROR: There is a syntax error near "where userid=40;"

    in short order, I

    1. reset passwords to usernames
    2. finally got around to writing that password reset script
    3. started using transactions.

Leave a comment on “A Classic Production Failure”

Log In or post as a guest

Replying to comment #:

« Return to Article