0

I have inserted a significant quantity of records into a table. Unfortunately, these records should not have been inserted in this table. Deletion of the records in a one-by-one fashion is not feasible.

How can one rollback the aforementioned records in this situation?

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Waheed
  • 10,086
  • 20
  • 53
  • 66

4 Answers4

2

Here are couple additional ideas you can try.

Restore a full backup in another database and then compare tables using some third party tools such as ApexSQL Data Diff or dbForge or Red Gate

If database was in full recovery mode try reading transaction log. Here are several posts on this topic:

SQL Server Transaction Log Explorer/Analyzer

Read the log file (*.LDF) in sql server 2008

How to view transaction logs in sql server 2008

Community
  • 1
  • 1
ScottS
  • 452
  • 4
  • 5
1

Assuming you were not inside a transaction when you did this, you're going to find the process painful. Not sure what flavour of DBMS you're interested in, but here's some info on SQL Server 2005:

Rollback transaction using transaction log

Essentially, the easiest way to do this is to restore your DB from a backup that predates your inserts.

Community
  • 1
  • 1
butterchicken
  • 13,583
  • 2
  • 33
  • 43
1

I am guessing the inserts statements have been committed to the database else you could simply do a ROLLBACK;

Do you have an audit table? If there is an audit table you would be able to identify the rows inserted during a particular datetime and then delete them...

Jaskirat
  • 1,114
  • 1
  • 8
  • 17
0

Are there any features of the inserted rows that make them distinguishable from all of the others? For example is there an inserted date, or a numeric identity column? If so, just do a delete based on that criteria.

Other than that, butterchicken is right, it's probably a bit painful. But I've never rolled back using a transaction log like that before.

Gavin
  • 9,855
  • 7
  • 49
  • 61
  • No i can't distinguish. Its not possible. – Waheed Aug 26 '09 at 09:11
  • it's fairly easy using the management studio gui - just select the 'point in time' restore option. – wefwfwefwe Aug 26 '09 at 09:12
  • You don't want to restore to a point in time in the current database as it will take away all the other records added to other tables since that point in time as well. You need to restore to a differnt database and then replace the table you are interested in. If other people would also have been inserting trecords into this table, you cannot use the restore to a point in time option at all without risking data integrity problems. – HLGEM Aug 26 '09 at 17:34