title: Batch delete - on error, are previous deleted records remain deleted?
body: <p>I have a large table with millions of records. When a procedure is executed, it deletes all records older then 20 minutes. </p>
  
  <p>Because, sometimes it take a lot of time, I decided to use batch deletes. I have run some test and it appears that I am gaining 20 seconds optimization, but I have started to wonder, what will happen if an error occurred during one of this delete statements - are previously deleted records remaining deleted or not?</p>
  
  <p>This is the SQL statement:</p>
  
  <pre><code>WHILE EXISTS (SELECT 1 FROM MyTable WHERE DATEADD(MINUTE,-20,GETUTCDATE()) &gt; [TimeAdded])
          BEGIN
              DELETE TOP (500000)
              FROM MyTable
              WHERE DATEADD(MINUTE,-20,GETUTCDATE()) &gt; [TimeAdded] 
  
              IF @@ERROR &lt;&gt; 0
                  BEGIN
                      RAISERROR (N'Delete operation from ''MyTable'' table failed.',10,0)
                      BREAK 
                  END
          END
  </code></pre>