I am in the process of creating a purge script in VBScript, which deletes records from tables if they are more than one month old.
The criteria for each table is different, and there are both parent and child tables (i.e. the latter is dependent on the former for retrieving ID codes and upload statuses).
My question: Should each DELETE
block for each table be created as a separate procedure, including child and parent deletions? How would this best and most efficiently be handled?
A sample of the SQL code:
DELETE FROM TestStaging.dbo.SpinDataEntries
WHERE TestStaging.dbo.SpinDataEntries.SpinDataId IN
(select TestStaging.dbo.SpinData.SpinDataId from TestStaging.dbo.SpinData
WHERE TestStaging.dbo.SpinData.UploadStatus in ('F', 'C')
AND LastUploaded < DATEADD (m,- 1,SYSDATETIME()));
DELETE FROM TestStaging.dbo.SpinData
WHERE TestStaging.dbo.SpinData.UploadStatus in ('F', 'C')
AND LastUploaded < DATEADD (m,- 1,SYSDATETIME());
Should each of these two blocks, as well as the remaining code, be logged as separate stored procedures, and then called from a separate, main VBScript?