Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Possible Duplicate:
How to rollback a deleted table data?

I accidentally ran an update statement against my database. Is there a way to roll back this single update without disrupting the rest of the database?

share|improve this question

migrated from stackoverflow.com Aug 28 '11 at 13:48

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Mark Henderson Aug 29 '11 at 1:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5  
What RDBMS? If SQL Server what is your recovery model and have you ever taken a full database backup? –  Martin Smith Aug 28 '11 at 13:37
6  
And that kids is why we always back up our database and test our update queries to see if they do what we want them to do! –  cularis Aug 28 '11 at 13:39

5 Answers 5

Not if you don't have a backup.

share|improve this answer

no, if the update has been completed successfully, I assume you used SQL Server Management Studio, the changes have been applied.

if it's really important that you revert those updates, you should restore the last backup if you have one and don't bother to loose changes done between backup time and now.

share|improve this answer

Were you in a transaction? If yes, try entering ROLLBACK WORK;

If you were not, than restore from backup

share|improve this answer

Get a backup restored, and rollforward to the point just before your accidental update. See http://msdn.microsoft.com/en-us/library/ms191455.aspx

share|improve this answer

Yes. You must shutdown your database and, using db admin tools, restore the database from the latest backup and roll forward through the log to a point in time just before your update. You will lose all updates made after that point of course, not just your accident.

I can't be more specific than that because you haven't shown which database you are using, but all databases have a log that can be used in this way.

share|improve this answer
1  
transaction log is to rollforward, not to rollback, unless the transaction had not done it's commit yet. –  Martin Aug 28 '11 at 13:48
3  
You are right - answer modified. btw, "its" has no apostrophe when used in the possessive, ie it should be done its commit. –  Bohemian Aug 28 '11 at 13:52