?
Solved

how to undo the last command in SQL Query analyzer?

Posted on 2004-10-03
6
Medium Priority
?
6,265 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 69

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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
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
Suggested Courses

762 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