rollback delete command

  • if by chance i run a delete command ,n sme rows from some table get deleted ,then what is the command to rollback the command or immediate command. so that i can retrieve the deleted rows

  • Good Day,

    You can use the "BEGIN TRAN" and "COMMIT TRAN" OR if you need to rollback then just use "ROLLBACK"

    BEGIN TRANSACTION @TranName;

    GO

    USE AdventureWorks;

    GO

    DELETE FROM AdventureWorks.HumanResources.JobCandidate

    WHERE JobCandidateID = 13;

    GO

    COMMIT TRANSACTION MyTransaction;

    GO

    The Rollback syntax

    ROLLBACK { TRAN | TRANSACTION }

    [ transaction_name | @tran_name_variable

    | savepoint_name | @savepoint_variable ]

    [ ; ]

    Hope this helps you

    regards

    Stephen

  • You can't recover deleted rows unless and untill you are using checkpoint. To rollback checkpoint is must.

    Resoultion:

    1. You can restore the backup with stop at otion and extract the data. (Best Option)

    2. You can use 3rd party tool to read the log and find out more. Not sure howfar it will help?

    ---------------------------------------------------
    "Thare are only 10 types of people in the world:
    Those who understand binary, and those who don't."

  • shiwani2002sg (7/18/2008)


    if by chance i run a delete command ,n sme rows from some table get deleted ,then what is the command to rollback the command or immediate command. so that i can retrieve the deleted rows

    Unless you started an explicit transaction before you ran the delete, there is no command that will retrieve the rows. You will have to locate a backup of the database.

    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
  • free_mascot (7/18/2008)


    You can't recover deleted rows unless and untill you are using checkpoint.

    Checkpoints happen automatically and just write dirty data pages to disk. It's BEGIN TRANSACTION that allows data modifications to be rolled back.

    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
  • GilaMonster (7/18/2008)


    shiwani2002sg (7/18/2008)


    if by chance i run a delete command ,n sme rows from some table get deleted ,then what is the command to rollback the command or immediate command. so that i can retrieve the deleted rows

    Unless you started an explicit transaction before you ran the delete, there is no command that will retrieve the rows. You will have to locate a backup of the database.

    If you need to revert to the backup, you may even want to explore some third party tools that allow you to do table and row level restore using the SQL Server backup. If the backup is older than you need, and you are desperate, you can also dig out a lot of information about the deleted rows from the transaction log.

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • GilaMonster (7/18/2008)


    free_mascot (7/18/2008)


    You can't recover deleted rows unless and untill you are using checkpoint.

    Checkpoints happen automatically and just write dirty data pages to disk. It's BEGIN TRANSACTION that allows data modifications to be rolled back.

    Hello Gail, you get about, don't you? 😀

    Let me ask you this; if he issues a Delete statement at 5pm, demolishing 50 rows in .05 seconds, could he not take a TLog backup at 5.05pm, and then do a point-in-time restore to 4.59Pm?

  • Providing he had a backup, had the DB in full recovery and had an unbroken log chain, yes. However that's not a rollback (which is what the question asked)

    p.s. 2 year old thread.

    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

Viewing 8 posts - 1 through 7 (of 7 total)

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