undo a sql statement

  • is it possible to undo an update statement which has updated my table .

    i was not useing any transaction but i directly updated it.

    now i want to recover old data and i dont have back also.

  • I cant think of anyway apart from back-ups.. as u said no back-ups and u dint open an explicit transaction, then i'm afraid your data is lost..

  • Restore from backup is the way to 'undo' changes. If you have no backup (why not?) then there's no practical way of undoing.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Is the db is full recovery mode?

    If so, the old data is still on the transaction log.

    Software is available that can pull that data from the log. Unfortunately, I think all such software now comes with an up-front $ cost.

    If the db is in simple mode, do an immediate tran log backup, as that is the only chance you have of keeping the data, although it might already have been truncated from the log.

    Scott Pletcher, SQL Server MVP 2008-2010

  • out of interest...what excactly did the update statement update?

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • There is no undo. Log software, as Scott mentioned, builds a reversing transaction, but it cannot undo the transaction.

    Restore from backup to another system, and then copy the data back. If the data from the full backup is not what you want, and you have log backups, then log software might still be needed.

  • scott.pletcher (7/27/2010)


    Software is available that can pull that data from the log. Unfortunately, I think all such software now comes with an up-front $ cost.

    $1000+ last time I checked.

    If the db is in simple mode, do an immediate tran log backup,...

    Log backups aren't possible in Simple recovery as the log is auto-truncated on checkpoint.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Yes, you have to change the db recovery mode and do a full backup first (or tell SQL you have done one). Then you can do a log backup.

    And, as I noted, yes, that is an extreme long shot. Most likely in simple mode the table data has already been truncated from the log.

    Scott Pletcher, SQL Server MVP 2008-2010

  • scott.pletcher (7/27/2010)


    Yes, you have to change the db recovery mode and do a full backup first (or tell SQL you have done one). Then you can do a log backup.

    I don't see why that would be useful. With the full backup starting the log chain, the log backup will only contain the log records from after the full backup.

    "Or tell SQL you have done one"

    ?? Elaborate please?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Perhaps. I thought SQL would still back up all active parts of the log. I was trying to cover all possibilities, since otherwise OP is in for a total data loss.

    Scott Pletcher, SQL Server MVP 2008-2010

  • For a special application, I've used triggers to record all changes to "backup" table. This allows modifications to be undone. It's a lot of code but the requirement was that any change had to be capable of being backed out.

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply