Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to undo the last command in SQL Query analyzer?

Posted on 2004-10-03
6
Medium Priority
?
6,277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 256 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 252 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 70

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 252 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

610 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