Skip to content

Instantly share code, notes, and snippets.

@jeffreypriebe
Forked from leekelleher/ForceEmptyRecycleBin.sql
Last active December 23, 2015 22:59
Show Gist options
  • Save jeffreypriebe/6706920 to your computer and use it in GitHub Desktop.
Save jeffreypriebe/6706920 to your computer and use it in GitHub Desktop.
-- Uncomment below to verify the number of nodes returned is the same as the number of nodes that is in the Recycle Bin
-- SELECT * FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20
--Setup the temporary table
CREATE TABLE #temp ([id] int);
INSERT #temp select id from umbracoNode where path like '%-20%' and id!=-20
-- Delete all 'related' nodes and table contents...
DELETE FROM cmsPreviewXml WHERE nodeId IN (SELECT id FROM #temp)
DELETE FROM cmsContentVersion WHERE contentId IN (SELECT id FROM #temp)
DELETE FROM cmsDocument WHERE nodeId IN (SELECT id FROM #temp)
DELETE FROM cmsContentXML WHERE nodeId IN (SELECT id FROM #temp)
DELETE FROM cmsContent WHERE nodeId IN (SELECT id FROM #temp)
DELETE FROM cmsPropertyData WHERE contentNodeId IN (SELECT id FROM #temp)
DELETE FROM umbracoUser2NodePermission WHERE nodeId IN (SELECT id FROM #temp)
DELETE FROM umbracoRelation where parentId in (select id from #temp) or childId in (select id from #temp)
-- remove fk constraint so that umbracoNode can delete
ALTER TABLE umbracoNode DROP CONSTRAINT FK_umbracoNode_umbracoNode
-- delete the XML nodes...
DELETE FROM umbracoNode WHERE id in (SELECT id FROM #temp)
-- re add fk constraint to umbracoNode
ALTER TABLE umbracoNode WITH NOCHECK ADD CONSTRAINT FK_umbracoNode_umbracoNode
FOREIGN KEY (parentId)
REFERENCES umbracoNode (id)
--Cleanup temp
DROP TABLE #temp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment