tsql - Batch delete - on error, are previous deleted records remain deleted? -


i have large table millions of records. when procedure executed, deletes records older 20 minutes.

because, take lot of time, decided use batch deletes. have run test , appears gaining 20 seconds optimization, have started wonder, happen if error occurred during 1 of delete statements - deleted records remaining deleted or not?

this sql statement:

while exists (select 1 mytable dateadd(minute,-20,getutcdate()) > [timeadded])         begin             delete top (500000)             mytable             dateadd(minute,-20,getutcdate()) > [timeadded]               if @@error <> 0                 begin                     raiserror (n'delete operation ''mytable'' table failed.',10,0)                     break                  end         end 

it depend on transactional mode run procedure.

but don't mind doesn't matter.

the thing may log error, fix cause of error , rerun code.

in case first run did delete records error, rerunning procedure resume @ point of delete error. in case did not delete records, rerunning procedure delete them.


Comments