49

You never estimate the importance of backups until you forgot the WHERE statement on a DELETE query.

Comments
  • 4
    I made it a habit to export the DB to a local instance then build and run the queries there.

    That way i always have a "recent" backup plus if i have a brainfart or whatever, i don't simultaneously have a heart attack :p
  • 1
    @lotd that’s what I usually do too, or I just clone the VM but I just had to manually delete a record because there was a bug on an ERP and oups 😬
  • 2
    Put your sql engine in safe delete mode. Then you cannot delete an entire table without adding WHERE 1=1
  • 1
    I once switched the "<" on my query deleting everything I wanted to stay, and commited.

    I made myself an bash script to create backup before I touch the DB. You gotta learn from your mistakes::)
  • 0
    There should be a tool that checks for that
  • 1
    @Krokoklemme or I should be less idiot ahaha or I could use transactions for everything
  • 0
    @cabrasm we all could do a lot of things better, but some just won't do it ^^

    Those tools would be useful for those people, and you could just kinda force them into it i.e by incorporating it into a build system
  • 0
    @Krokoklemme well I do agree partially, you shouldn’t write queries on a daily basis on a db, therefore if you type stuff in there you should be able to know what you do, but more security is a good thing indeed
  • 0
    @jespersh yeah that’s true but I prefer to use transactions, you can also screw up an UPDATE query the same way
  • 1
    @Bitwise I normally avoid too touching dbs that much and started having SQL scripts on our repo with templates (ie db or table cursors, index defragmentation etc), but sometimes I’m just like “ok i just have to update this client name because app is bugging” and it ends up having all clients named Bossy.
  • 0
    I've lost a few hundred email addresses similarly. Nowdays I just write queries as select, and after validating the filter, change them to delete / update. But yeah, I probably shouldn't write ad-hoc queries against a prod DB anyways...
Add Comment