/* This script will purge the filestore of orphaned files. It does the same thing as the Robot job, but avoids issues with service timeout. */ -- Get a count of the number of orphaned files, then run the delete in chunks until done DECLARE @COUNTER INT = (SELECT COUNT(*) FROM FileStore WHERE FileID NOT IN (SELECT FileUri FROM DocumentInfo) AND FileID NOT IN (SELECT FileUri FROM TemplateInfo)); WHILE @COUNTER > 0 BEGIN DELETE TOP (100) FROM [FileStore] WHERE [FileID] NOT IN (SELECT [FileUri] FROM [DocumentInfo]) AND [FileID] NOT IN (SELECT [FileUri] FROM [TemplateInfo]); SET @COUNTER = @COUNTER - 100; END;