Skip to content

Instantly share code, notes, and snippets.

@azcoov
Created August 16, 2011 07:08
Show Gist options
  • Save azcoov/1148587 to your computer and use it in GitHub Desktop.
Save azcoov/1148587 to your computer and use it in GitHub Desktop.
SQL Simple Batch Delete
declare
@CurCount int, @MaxCount int
set @CurCount = 0
set @MaxCount = 100000
set nocount on;
while 1 = 1
begin
delete top(1000)
[TableName]
where
[SomeDateColumn] < dateadd(dd, -14, getdate()) -- Date column is just an example
select @CurCount = @CurCount + 1000
if @@rowcount = 0 break
if @CurCount < = @MaxCount break
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment