La cancellazione attraveso DELETE di una grande quantità di dati è tipicamente molto lenta. Un modo per accelerare la cancellazione è quell di cancellare un set di righe per volta e non tutte insieme:
[code]
DECLARE @Count INT
Declare @for_delete INT
Declare @chunk_size INT
SELECT @chunk_size=100000
SELECT @Count = 0
select @for_delete=count(*) from [Your big table] where [Your Where Clause]
While (@Count < @for_delete)
BEGIN
SELECT @Count = @Count + @chunk_size
BEGIN TRAN
DELETE top(@chunk_size) FROM [Your big table] where [Your Where Clause]
COMMIT TRAN
END
[/code]
il chunk_size è modificabile a piacere e vi garantisco che la velocità di cancellazione è decisamente superiore.
Nessun commento:
Posta un commento