Solved

how to undo the last command in SQL Query analyzer?

Posted on 2004-10-03
6
6,250 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:ScottPletcher
ScottPletcher 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

743 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

10 Experts available now in Live!

Get 1:1 Help Now