<p>For example: Updating all rows of the customer table because you forgot to add the where clause.</p>

<ol>
<li>What was it like, realizing it and reporting it to your coworkers or customers? </li>
<li>What were the lessons learned?</li>
</ol>

[{'answer_id': 12143, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>I dropped the live database and deleted it.</p>\n\n<p>Lesson learned: ensure you know your SQL - and make sure that you back up before you touch stuff.</p>\n'}, {'answer_id': 12145, 'author': 'Keith', 'author_id': 905, 'author_profile': 'https://Stackoverflow.com/users/905', 'pm_score': 3, 'selected': False, 'text': '<p>A junior DBA meant to do:</p>\n\n<pre><code>delete from [table] where [condition]\n</code></pre>\n\n<p>Instead they typed:</p>\n\n<pre><code>delete [table] where [condition]\n</code></pre>\n\n<p>Which is valid T-Sql but basically ignores the where [condition] bit completely (at least it did back then on MSSQL 2000/97 - I forget which) and wipes the entire table.</p>\n\n<p>That was fun :-/</p>\n'}, {'answer_id': 12146, 'author': 'Mike Woodhouse', 'author_id': 1060, 'author_profile': 'https://Stackoverflow.com/users/1060', 'pm_score': 1, 'selected': False, 'text': "<p>I discovered I didn't understand Oracle redo log files (terminology? it was a long time ago) and lost a weeks' trade data, which had to be manually re-keyed from paper tickets.</p>\n\n<p>There <em>was</em> a silver lining - during the weekend I spent inputting, I learned a lot about the useability of my trade input screen, which improved dramatically thereafter.</p>\n"}, {'answer_id': 12149, 'author': 'Surgical Coder', 'author_id': 1276, 'author_profile': 'https://Stackoverflow.com/users/1276', 'pm_score': 4, 'selected': False, 'text': '<p>I think my worst mistake was</p>\n\n<pre><code>truncate table Customers\ntruncate table Transactions\n</code></pre>\n\n<p>I didnt see what MSSQL server I was logged into, I wanted to clear my local copy out...The familiar "OH s**t" when it was taking significantly longer than about half a second to delete, my boss noticed I went visibily white, and asked what I just did. About half a mintue later, our site monitor went nuts and started emailing us saying the site was down. </p>\n\n<p>Lesson learned? Never keep a connection open to live DB longer than absolutly needed.</p>\n\n<p>Was only up till 4am restoring the data from the backups too! My boss felt sorry for me, and bought me dinner...</p>\n'}, {'answer_id': 12150, 'author': 'ninesided', 'author_id': 1030, 'author_profile': 'https://Stackoverflow.com/users/1030', 'pm_score': 1, 'selected': False, 'text': '<p>Worst case scenario for most people is production data loss, but if they\'re not running nightly backups or replicating data to a DR site, then they deserve everything they get!</p>\n\n<p>@<a href="https://stackoverflow.com/questions/12141/whats-your-worst-database-accident-happened-in-production#12145">Keith</a> in T-SQL, isn\'t the FROM keyword optional for a DELETE? Both of those statements do exactly the same thing...</p>\n'}, {'answer_id': 12227, 'author': 'Marshall', 'author_id': 1302, 'author_profile': 'https://Stackoverflow.com/users/1302', 'pm_score': 3, 'selected': False, 'text': "<p>I work for a small e-commerce company, there's 2 developers and a DBA, me being one of the developers. I'm normally not in the habit of updating production data on the fly, if we have stored procedures we've changed we put them through source control and have an officially deployment routine setup.</p>\n\n<p>Well anyways a user came to me needing an update done to our contact database, batch updating a bunch of facilities. So I wrote out the query in our test environment, something like</p>\n\n<pre><code>update facilities set address1 = '123 Fake Street'\n    where facilityid in (1, 2, 3)\n</code></pre>\n\n<p>Something like that. Ran it in test, 3 rows updated. Copied it to clipboard, pasted it in terminal services on our production sql box, ran it, watched in horror as it took 5 seconds to execute and updated 100000 rows. Somehow I copied the first line and not the second, and wasn't paying attention as I <kbd>CTRL</kbd> + <kbd>V</kbd>, <kbd>CTRL</kbd> + <kbd>E</kbd>'d.</p>\n\n<p>My DBA, an older Greek gentleman, probably the grumpiest person I've met was not thrilled. Luckily we had a backup, and it didn't break any pages, luckily that field is only really for display purposes (and billing/shipping).</p>\n\n<p>Lesson learned was pay attention to what you're copying and pasting, probably some others too.</p>\n"}, {'answer_id': 12233, 'author': 'Jedi Master Spooky', 'author_id': 1154, 'author_profile': 'https://Stackoverflow.com/users/1154', 'pm_score': 1, 'selected': False, 'text': '<p>The worst thing that happened to me was that a Production server consume all the space in the HD.  I was using SQL Server so I see the database files and see that the log was about 10 Gb so I decide to do what I always do when I want to trunc a Log file. I did a Detach the delete the log file and then attach again. Well I realize that if the log file is not close properly this procedure does not work. so I end up with a mdf file and no log file. Thankfully I went to the Microsoft site I get a way to restore the database as recovery and move to another database.</p>\n'}, {'answer_id': 12280, 'author': 'Seibar', 'author_id': 357, 'author_profile': 'https://Stackoverflow.com/users/357', 'pm_score': 2, 'selected': False, 'text': "<pre><code>update Customers set ModifyUser = 'Terrapin'\n</code></pre>\n\n<p>I forgot the where clause - pretty innocent, but on a table with 5000+ customers, my name will be on every record for a while...</p>\n\n<p>Lesson learned: use transaction commit and rollback!</p>\n"}, {'answer_id': 12299, 'author': 'Stu', 'author_id': 414, 'author_profile': 'https://Stackoverflow.com/users/414', 'pm_score': 2, 'selected': False, 'text': '<p>I once managed to write an updating cursor that never exited. On a 2M+ row table. The locks just escalated and escalated until this 16-core, 8GB RAM (in 2002!) box actually ground to a halt (of the blue screen variety).</p>\n'}, {'answer_id': 12404, 'author': 'travis', 'author_id': 1414, 'author_profile': 'https://Stackoverflow.com/users/1414', 'pm_score': 3, 'selected': False, 'text': '<p>About 7 years ago, I was generating a change script for a client\'s DB after working late. I had only changed stored procedures but when I generated the SQL I had "script dependent objects" checked. I ran it on my local machine and all appeared to work well. I ran it on the client\'s server and the script succeeded. </p>\n\n<p>Then I loaded the web site and the site was empty. To my horror, the "script dependent objects" setting did a <code>DROP TABLE</code> for every table that my stored procedures touched. </p>\n\n<p>I immediately called the lead dev and boss letting them know what happened and asking where the latest backup of the DB could be located. 2 other devs were conferenced in and the conclusion we came to was that no backup system was even in place and no data could be restored. The client lost their entire website\'s content and I was the root cause. The result was a <strong>$5000</strong> credit given to our client.</p>\n\n<p>For me it was a great lesson, and now I am super-cautious about running any change scripts, and backing up DBs first. I\'m still with the same company today, and whenever the jokes come up about backups or database scripts someone always brings up the famous "DROP TABLE" incident.</p>\n'}, {'answer_id': 12419, 'author': 'sven', 'author_id': 46, 'author_profile': 'https://Stackoverflow.com/users/46', 'pm_score': 2, 'selected': False, 'text': "<p>I thought I was working in the testing DB (which wasn't the case apparently), so when I finished 'testing' I run a script to reset <em>all</em> data back to the standard test data we use... ouch!<br>\nLuckily this happened on a database that had backups in place, so after figuring out I did something wrong we could easily bring back the original database.</p>\n\n<p>However this incident did teach the company I worked for to <em>realy</em> seperate the production and the test environment.</p>\n"}, {'answer_id': 12559, 'author': 'Mark Harrison', 'author_id': 116, 'author_profile': 'https://Stackoverflow.com/users/116', 'pm_score': 2, 'selected': False, 'text': "<p>We were trying to fix a busted node on an Oracle cluster.</p>\n\n<p>The storage management module was having problems, so we clicked the un-install button with the intention of re-installing and copying the configuration over from another node.</p>\n\n<p>Hmm, it turns out the un-install button applied to the entire cluster, so it cheerfully removed the storage management module from all the nodes in the system.</p>\n\n<p>Causing every node in the production cluster to crash.  And since none of the nodes had a storage manager, they wouldn't come up!</p>\n\n<p>Here's an interesting fact about backups... the oldest backups get rotated off-site, and you know what your oldest files on a database are?  The configuration files that got set up when the system was installed.</p>\n\n<p>So we had to have the offsite people send a courier with that tape, and a couple of hours later we had everything reinstalled and running.  Now we keep local copies of the installation and configuration files!</p>\n"}, {'answer_id': 21832, 'author': 'vikramjb', 'author_id': 2245, 'author_profile': 'https://Stackoverflow.com/users/2245', 'pm_score': 1, 'selected': False, 'text': "<blockquote>\n  <p>Updating all rows of the customer table because you forgot to add the where clause.</p>\n</blockquote>\n\n<p>That was exactly i did :| . I had updated the password column for all users to a sample string i had typed onto the console. The worst part of it was i was accessing the production server and i was checking out some queries when i did this. My seniors then had to revert an old backup and had to field some calls from some really disgruntled customers. Ofcourse there is another time when i did use the delete statement, which i don't even want to talk about ;-)</p>\n"}, {'answer_id': 36677, 'author': 'Telcontar', 'author_id': 518, 'author_profile': 'https://Stackoverflow.com/users/518', 'pm_score': 1, 'selected': False, 'text': "<blockquote>\n  <p>Truncate table T_DAT_STORE</p>\n</blockquote>\n\n<p>T_DAT_STORE was the fact table of the department I work in. I think I was connected to the development database. Fortunately, we have a daily backup, which hasn't been used until that day, and the data was restored in six hours.</p>\n\n<p>Since then I revise everything before a truncate, and periodically I ask for a backup restoration of minor tables only to check the backup is doing well (Backup isn't done by my department)</p>\n"}, {'answer_id': 128358, 'author': 'Oli', 'author_id': 15296, 'author_profile': 'https://Stackoverflow.com/users/15296', 'pm_score': 2, 'selected': False, 'text': "<p>I don't remember all the sql statements that ran out of control but I have one lesson learned - <strong>do it in a transaction</strong> if you can (beware of the big logfiles!). </p>\n\n<p>In production, if you can, proceed the old fashioned way:</p>\n\n<ol>\n<li>Use a maintenance window</li>\n<li>Backup</li>\n<li>Perform your change</li>\n<li><strong>verify</strong></li>\n<li>restore if something went wrong</li>\n</ol>\n\n<p>Pretty uncool, but generally working and even possible to give this procedure to somebody else to run it during their night shift while you're getting your well deserved sleep :-)</p>\n"}, {'answer_id': 312935, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>This didn't happen to me, just a customer of ours whos mess I had to clean up.</p>\n\n<p>They had a SQL server running on a RAID5 disk array - nice hotswap drives complete with lighted disk status indicators.  Green = Good, Red = Bad.</p>\n\n<p>One of their drives turned from green to red and the genius who was told to pull and replace the (Red) bad drive takes a (Green) good one out instead.  Well this didn't quite manage to bring down the raid set completely - opting for the somewhat readable (Red) vs unavaliable (Green) for several minutes.. after realizing the mistake and swapping the drives back any data blocks that were written during this time became jyberish as disk synchronization was lost) ... 24-straight hours later writing meta programs to recover readable data and reconstruct a medium sized schema they were back up and running.</p>\n\n<p>Morals of this story include...Never use RAID5, always maintain backups, careful who you hire.</p>\n\n<p>I made a major mistake on a customers production system once -- luckily while wondering why the command was taking so long to execute realized what I had done and canceled it before the world came to an end.</p>\n\n<p>Moral of this story include ... always start a new transaction before changing ANYTHING, test the results are what you expect and then and only then commit the transaction.</p>\n\n<p>As a general observation many classes of rm -rf / type errors can be prevented by properly defining foreign key constraints on your schema and staying far away from any command labled 'CASCADE'</p>\n"}, {'answer_id': 313022, 'author': 'MBCook', 'author_id': 18189, 'author_profile': 'https://Stackoverflow.com/users/18189', 'pm_score': 2, 'selected': False, 'text': '<p>I did exactly what you suggested. I updated all the rows in a table that held customer documents because I forgot to add the "where ID = 5" at the end. That was a mistake.</p>\n\n<p>But I was smart and paranoid. I knew I would screw up one day. I had issued a "start transaction". I issued a rollback and then checked the table was OK.</p>\n\n<p><strong>It wasn\'t.</strong></p>\n\n<p>Lesson learned in production: despite the fact we like to use InnoDB tables in MySQL for many MANY reasons... be SURE you haven\'t managed to find one of the few MyISAM tables that doesn\'t respect transactions and you can\'t roll back on. Don\'t trust MySQL under any circumstances, and habitually issuing a "start transaction" is a good thing. Even in the worst case scenario (what happened here) it didn\'t hurt anything and it would have protected me on the InnoDB tables.</p>\n\n<p>I had to restore the table from a backup. Luckily we have nightly backups, the data almost never changes, and the table is a few dozen rows so it was near instantaneous. For reference, no one knew that we still had non-InnoDB tables around, we thought we converted them all long ago. No one told me to look out for this gotcha, no one knew it was there. My boss would have done the same exact thing (if he had hit enter too early before typing the where clause too).</p>\n'}, {'answer_id': 313038, 'author': 'Jordan Stewart', 'author_id': 33338, 'author_profile': 'https://Stackoverflow.com/users/33338', 'pm_score': 3, 'selected': False, 'text': '<p>Something to the effect of:</p>\n\n<blockquote>\n  <p><code>update email set processedTime=null,sentTime=null</code></p>\n</blockquote>\n\n<p>on a production newsletter database, resending every email in the database.</p>\n'}]
['https://Stackoverflow.com/questions/12141', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/990/']