I have a list of about 2,300K rows of bad data that I'd like to delete from my database. Is there a way that I can delete all of these rows using a single sql statement? I can 'WHERE IN' but the issue is that these values are not quoted and fail. Thanks
A:
CSV? Could you instead make a list of the good rows, drop the table, and insert the good rows?
lod3n
2009-09-24 20:12:18
Sure, I guess that's also an option. I didn't think of that. :)
2009-09-24 20:17:23
Thinking about it now... I don't know how I'd do that. How would I distinguish between the good rows and bad? I'd still have to use the CSV list to get the good rows, no?
2009-09-24 20:19:08
A:
Use SQL and a little editor regex-fu:
- Use excel or whatever to to get the list of keys you want to delete.
- Copy that list into your favorite text editor. (Ultraedit, editplus, notepad++, heck even pfe)
- Search replace string: \n => ',' (newline becomes quote comma quote)
- Add a quote to the beginning and end of the list, surround by parenthesis, and stick in your WHERE IN clause.
- Good to go.
Byron Whitlock
2009-09-24 20:19:05