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 DevarajanRank #342 · 7.3K reputationPosted Sep 23, 2016, 12:53 PM EDT
Guest UserRank #2,002 · 726 reputationPosted Sep 24, 2016, 10:19 PM EDT
Nepethya RanaRank #4,361 · 348 reputationPosted Sep 25, 2016, 11:56 PM EDT
@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
Nigel FernandesRank #753 · 3.1K reputationPosted Sep 28, 2016, 7:02 PM EDT