This might help, it is a script I have used in the past for handling Orphaned documents:
BEGIN TRAN;
--DROP TABLE #Orphans
SELECT ct.NodeID INTO #Orphans
FROM cms_tree ct
WHERE ct.NodeParentID NOT IN(
SELECT ct.NodeID
FROM dbo.CMS_Tree ct )
AND NodeAliasPath != '/';
--Abandon Orpans
DELETE FROM dbo.CMS_EventLog
WHERE dbo.CMS_EventLog.NodeID IN( SELECT *
FROM #Orphans );
DELETE FROM dbo.CMS_DocumentAlias
WHERE dbo.CMS_DocumentAlias.AliasNodeID IN( SELECT *
FROM #Orphans );
DELETE FROM dbo.CMS_Attachment
WHERE dbo.CMS_Attachment.AttachmentDocumentID IN( SELECT cd.DocumentID
FROM dbo.CMS_Document cd
WHERE cd.DocumentNodeID IN(
SELECT *
FROM #Orphans o ));
DELETE FROM dbo.CMS_DocumentTag
WHERE dbo.CMS_DocumentTag.DocumentID IN( SELECT cd.DocumentID
FROM dbo.CMS_Document cd
WHERE cd.DocumentNodeID IN(
SELECT *
FROM #Orphans ));
DELETE FROM dbo.Blog_Comment
WHERE dbo.Blog_Comment.CommentPostDocumentID IN( SELECT cd.DocumentID
FROM dbo.CMS_Document cd
WHERE cd.DocumentNodeID IN(
SELECT *
FROM #Orphans ));
DELETE FROM dbo.CMS_Document
WHERE dbo.CMS_Document.DocumentNodeID IN( SELECT *
FROM #Orphans );
DELETE FROM CMS_tree
WHERE CMS_tree.NodeID IN( SELECT *
FROM #Orphans );
COMMIT;
--ROLLBACK