Solved

how to undo the last command in SQL Query analyzer?

Posted on 2004-10-03
6
6,257 Views
Last Modified: 2009-07-29
hello guys, I'm desperately need your help immediately.

i have issued a statement on my sql query analyzer that change all other record on a table. how do i undo this statement?

e.g.

instead of committing this statement

update table1 set column1 = 'a' where column2 = '1' and column3 = '2' and column1 <> 'z'

i typed the wrong statement

update table1 set column1 = 'a' where column1 <> 'z'

which changes all other record on table 1 rather than records with column1 = 'z'

here's the question. How do i undo the statement like we do to undo the last action in msword, msexcel and other app programs.

sorry about this question, all i got is 190 points. Please help me right now. I've been balancing this records to reconcile the subsidiary ledgers.


thanks.
0
Comment
Question by:elatagaw
6 Comments
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 64 total points
ID: 12214291
There is no Undo in SQL Server. You either have to restore from backup, or use a 3rd party tool that can undo from the Log files -- however, if your log files get reused or wiped, it will be impossible even for 3rd party tools. Unfortunately, it costs. The best tool is Log Explorer from Lumigent (www.lumigent.com). There's a trial version, but it only works with SQL Server sample databases pubs and Northwind.
0
 
LVL 1

Assisted Solution

by:AntonG
AntonG earned 63 total points
ID: 12214849
i must agree with jdlambert1.... what he says there is quite accurate.

In future, you should try to wrap Transactional statements around your queries.

That way, you could always ROLLBACK the transactions, but unfortunately, the situation you are currently in sort of renders you helpless.
0
 
LVL 69

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 63 total points
ID: 12218007
If you have a db backup and log backup, you could also forward recover the db to the point just before you issued the command.  For example, if the command was issused at 11:17a, roll forward to 11:16a (or 11:15a to be safe).

Btw, as you now know, it is safest to always first run UPDATE as SELECT and *make sure* it affects only the row(s) you expect it to effect.  So, instead of starting with:

update table1
set column1 = 'a'
where column1 <> 'z'

Start with:

SELECT *
FROM table1
WHERE column1 <> 'z'

Then, if the number of rows and values look OK, then you issue the UPDATE (or DELETE).
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now