Accidently update a table, How can I recover??

Posted on 2005-05-09
Last Modified: 2012-05-05
Hi, Guru,

I accidently update the wrong rows of one table in the MS SQL server through Query Analyzer. How can I recover the old result? Somebody said the "ROLLBACK". But it gave me the error: "The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION."

I am new on the Database, how can I recover the old result? Thanks.

Question by:suwanee
    LVL 65

    Accepted Solution

    You can't.  Do you have a backup, and can you modify the UPDATE query to effectively un-do the previous one?

    The rollback you are referring to is when you use transactions in code, and surround your queries in them.  Using Access VBA it goes like this...
    Dim cn as ADODB.Connection
    Set cn = CurrentProject.Connection


    cn.Execute "Query 1"
    cn.Execute "Query 2"
    cn.Execute "Query 3"

    If Whatever then 'error trapping, records affected, whatever criteria you want...
    End If

    Hope this helps.

    Author Comment

    No, I don't have backup, and I don't know the old results. It got to be a problem.
    LVL 65

    Expert Comment

    by:Jim Horn
    You may be hosed here.  Can you re-import the table from whatever the source of its data was?

    LVL 25

    Assisted Solution

    There are a couple of products that might help you (free trials).  They both read the transaction logs and allow for changes to be undone.

    Go here:

    Look for ApexSQL Log.  It is supposed to generate Undo scripts for you.

    Or try Lumigent's Log Explorer:

    You should be able to "Undo a single operation or multiple transactions" with this product.
    LVL 8

    Expert Comment

    On the bright side, you may have your first really good example of "Why we must do backups". If you cant recover the data you may want to keep a record of this incident to refer to whenever you are getting a bit lazy on the backup front, or when someone tells you that you dont really need backups.

    LVL 50

    Assisted Solution

    by:Julian Hansen
    Here is a tip for the future.

    I had a similar problem a while back and it cost me dearly. Since then I do the following when making any data changes to my database.

    Assume QA

    Before making changes to the database run the following command


    Now do all the updates you want - make sure you don't close your session or you will kill the transaction frame

    After updates check that all is well - if you are happy run the following


    if you are not run


    This is not a substitute for backups but is a useful technique to avoid having to use the backups.

    LVL 8

    Expert Comment

    I think Jim and Jrb both supplied pertinent answers given the information they had at the time. I feel my advice is just as applicable as julians, given that by the time julian answered we knew that the transaction had not been declared. For future use, my advice on backups is just as if not more useful than transaction rollback syntax.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction If you are not already aware of what you could use a table with sequential integer values for in SQL, you can read Delimited String Parsing in SQL Server 2005 or later ( by BrandonGalderisi (h…
    This article describes some very basic things about SQL Server filegroups.
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 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

    26 Experts available now in Live!

    Get 1:1 Help Now