Does cancelling a "DELETE" query stop any rows from being deleted?

Rachel Halper 0 Reputation points
2023-12-12T00:05:56.61+00:00

Hi all,

I started running a "DELETE FROM (table)" query and realized I needed to change something so I hit cancel. It was successful and no rows were said to be affected, but does cancelling successfully stop any rows from being deleted or can a few be deleted still?

Thank you.

Developer technologies | Transact-SQL
SQL Server | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Vahid Ghafarpour 23,385 Reputation points Volunteer Moderator
    2023-12-12T02:44:46.0466667+00:00

    Thanks for posting your question in the Microsoft Q&A forum.
    If the cancellation is successful, SQL Server will initiate a rollback operation to undo the changes made by the incomplete DELETE operation. The rows should be there. Delete is rolled back if you cancel the statement.

    The database should be restored to its state before the DELETE operation was initiated.

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful **

    0 comments No comments

  2. Anonymous
    2023-12-12T03:16:36.91+00:00

    Hi @Rachel Halper

    As long as the delete was in one single transaction, it should rollback to the preview state.

    To avoid encountering this situation again, you should build good habits.

    You can refer to this post for more advice.

    https://www.reddit.com/r/SQL/comments/18fxpgi/does_cancelling_a_delete_stop_any_row_removal/?rdt=58313

    Best regards,

    Percy Tang

    0 comments No comments

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.