Syntax to create store proc to delete huge receords
I need to create a store procedure with a loop that takes two parameter numOfRowsToDelete and delayTime so that store proc delete the that numOfrows and wait for the delayTime and run again. How do I do it. I am new to database. Please help me
Madhanmohan DevarajanPosted Sep 23, 2016, 4:53 PM
Nigel FernandesPosted Sep 28, 2016, 11:02 PM
Nepethya RanaPosted Sep 26, 2016, 3:56 AM
@DeleteBatchSize INT,
@DelayTime DATETIME
AS
BEGIN
SET NOCOUNT ON;
DECLARE @DeleteRowCount INT
SET @DeleteRowCount = 1
WHILE (@DeleteRowCount > 0)
BEGIN
BEGIN TRANSACTION
DELETE TOP(@DeleteBatchSize) SchemaTableName;
SET @DeleteRowCount = @@ROWCOUNT;
PRINT @DeleteRowCount;
COMMIT
WAITFOR DELAY @DelayTime
END
END
GO
Guest UserPosted Sep 25, 2016, 2:19 AM