How to force a rollback of SQL Server to stop

knt1N 286 Reputation points
2021-05-14T17:57:56.857+00:00

I'm registering or updating a lot of data in DB in SQL Server.
Due to circumstances, this transaction is a very large unit, and if an error occurs, a rollback of more than 24 hours occurs.
In this situation, is there an emergency way to force the rollback to stop?

・"SQL Server 2017 Standerd" is used.
・This DB is for verification only, and I do not care if the data is damaged. The DB recovery model is "simple", and I restore it using a DB backup I made before. In the worst case, reinstall SQL Server itself.

I'd appreciate it if someone could answer my questions.

SQL Server Other
{count} votes

Accepted answer
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2021-05-14T21:31:47.127+00:00

    And if what Tom says does not work out:

    1. Stop SQL Server.
    2. Delete the files for the database.
    3. Start SQL Server.
    4. Drop the database.

    I am not fully sure that the last step will work, but if it does not: create a new database, stop SQL Server and copy the files of the new database to the place of the old database.

    But be very careful when you play this game, so that you don't delete database files you really want to keep!

    2 people found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Tom Phillips 17,771 Reputation points
    2021-05-14T18:36:34.407+00:00

    If you don't care about damaging the database, you can try restarting the SQL Server service (sometimes twice) and it may stop the rollback and mark the database as "suspect" Then you can drop the database.

    I do not recommend doing that normally or on a production server.


  2. Jeffrey Williams 1,896 Reputation points
    2021-05-16T16:31:57.183+00:00

    You may have better luck modifying the process to batch the changes - instead of trying to perform everything in a single batch that has to be rolled back. You also may find that batching the changes performs much better than a single transaction.

    This way - if an error occurs - only the latest batch has to roll back and that will be much smaller in scope and impact.


  3. CathyJi-MSFT 22,396 Reputation points Microsoft External Staff
    2021-05-17T07:32:24.727+00:00

    Hi @knt1N ,

    Patience is the key in such scenarios. Rollback process to leave the database in an consistent state. First we cannot KILL a process which is in ROLLBACK state. When a process is in ROLLBACK state it has to complete its work only then it will come back to normal. If we try to restart SQL Server then recovery of the database will take time and during Rollforward-Rollback phase it will again wait for this transaction to be complete.

    We can check the Percentage of ROLLBACK done using below command.

    KILL 60 WITH STATUSONLY  
    

    *where 60 is SPID which is doing ROLLBACK.

    Check if this similar thread could help you.


    If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.