LinkedIn

Thursday, 4 December 2008

Batch Deleting in T-SQL


DECLARE @BatchSize int


DECLARE @Rows int

SET @Rows = 1

SET @BatchSize = 100000

WHILE (@Rows > 0)

BEGIN

delete TOP (@BatchSize) FROM PropertyMonthProperty
from PropertyMonthProperty PMP
inner join Property P
on
PMP.propertyid = P.propertyid
where
p.scenarioid = 14149

SET @Rows = @@ROWCOUNT

END