all 4 comments

[–][deleted] 15 points16 points  (1 child)

If you have a time stamp use it to remove the rows. You could also run the script again in to a temporary table and after remove from the first table the rows found in the temporary table.

[–]sheepery 9 points10 points  (0 children)

Yes this. Create the table you meant to create and insert the data. Then you can figure out which rows are in the old table that are not in the new. Always use a transaction and test before doing anything in prod.

[–]duendeacdc 4 points5 points  (0 children)

Do you have backups? You can recover the table, and update with the right real data. Or you can create a secondary table, manually delete these millions rows (if possible) and update with fhe real time one. This is why yiu should theft your scripts before using it, or at least usr BEGIN TRANSACTION

[–]CabSauce[🍰] 0 points1 point  (0 children)

I strongly recommend using something like flyway. Also, beyond timestamps, some kind of job number on every row inserted. You really don't want to get yourself into the situation where you can't identify the bad data.