Delete Data from DB efficiently
--Loop the data and than delete the data
While (select Count(*) from [dbo].[Export_Task] WHERE TaskID < 1076044) > 0
BEGIN
DELETE TOP(10000) FROM [dbo].[Export_Task]
END
While (select Count(*) from [dbo].[Export_Task]) > 0
BEGIN
DELETE TOP(10000) FROM [dbo].[Export_Task]
END
--Deletes the Sync log
select Count(*) from [dbo].[Integration_SyncLog] GO
While (select Count(*) from [dbo].[Integration_SyncLog]) > 0
BEGIN
DELETE TOP(3000) FROM [dbo].[Integration_SyncLog]
END
GO
--Deletes the Sync Data
SELECT COUNT ([SynchronizationID]) FROM [dbo].[Integration_Synchronization] GO
While (select Count(*) from [dbo].[Integration_Synchronization]) > 0
BEGIN
DELETE TOP(100) FROM [dbo].[Integration_Synchronization]
END
GO
--Deletes the Sync tasks
SELECT COUNT([TaskID]) FROM [dbo].[Integration_Task] GO
While (select Count(*) from [dbo].[Integration_Task]) > 0
BEGIN
DELETE TOP(100) FROM [dbo].[Integration_Task]
END
GO
While (select Count(*) from [dbo].[CMS_Email] WHERE EMailStatus = 1) > 0
BEGIN
DELETE TOP(50) FROM [dbo].[CMS_Email] WHERE EMailStatus = 1
END