tags:

views:

1441

answers:

7

I just did a delete from table

How do I roll back or undelete the rows??

+2  A: 

restore from a backup.

AlexCuse
+7  A: 

if you called begin transaction before you did it, and have not yet called commit, then you can call rollback, otherwise... you're gonna have to restore

Wes P
Scott, I think you should see Mark Brackett's answer. Based on your post, you probably didn't called Begin Transaction. But this is the right answer on how to roll something back if you began a transaction.
Cervo
A: 

if you prefaced the delete with a begin tran you just use rollback tran

if not, start looking for your backups.

Kevin
A: 
rollback;

But only if you were in a transaction..

Oli
A: 

I did this once on a database with no backups and was able to recover the data using a utility that replayed all the transaction log entries. Fortunately in my situation I had never truncated the transaction log.

JC
Oh Snap. Btw, was it Lumigent? I haven't seen any others but if you know of a good free or cheap one I'd love to hear about it?
Meff
Don't remember, it was a trial version of something from 2002.
JC
+1  A: 

This will do the trick, assuming you have the money: http://www.lumigent.com/products/log_explorer.html

Apart from that, backups, like everyone else said

Meff
Back in 2002 I remember using something similar but the trial version was enough for me to get the data back.
JC
+3  A: 

Assuming you have a recent full backup of your database, backup your transaction log now, and restore it to a point in time prior to your delete. If there's live data that's been changed since then, you'll probably want to restore it to a different DB, and manually insert the deleted records.

From memory, so syntax may be a bit off - but you get the idea:

BACKUP LOG DBName
   TO DISK='C:\DBName.TRN'
GO

RESTORE DATABASE DBName2
   FROM DISK='C:\DBName.BAK'
   WITH 
       MOVE 'DBName.MDF' TO 'C:\DBName2.MDF',
       MOVE 'DBName.LDF' TO 'C:\DBName2.LDF',
       NORECOVERY
GO

RESTORE LOG DBName2
   FROM DISK='C:\DBName.TRN'
   WITH
       RECOVERY,
       STOPAT = '09/26/2008 17:00'
GO
Mark Brackett
I'm not sure about your exact syntax as I have never done this myself ... thankfully ... but I think this is definitely the right direction!
mattruma
I think that this is the right answer. If the poster is asking how to undelete, he probably didn't begin tran.
Cervo