Skip to content

Instantly share code, notes, and snippets.

@leekelleher
Last active July 18, 2020 11:15
Show Gist options
  • Save leekelleher/1171298 to your computer and use it in GitHub Desktop.
Save leekelleher/1171298 to your computer and use it in GitHub Desktop.
Umbraco: Force empty the Recycle Bin
-- 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
-- Delete all 'related' nodes and table contents...
DELETE FROM cmsPreviewXml WHERE nodeId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)
DELETE FROM cmsContentVersion WHERE contentId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)
DELETE FROM cmsDocument WHERE nodeId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)
DELETE FROM cmsContentXML WHERE nodeId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)
DELETE FROM cmsContent WHERE nodeId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)
DELETE FROM cmsPropertyData WHERE contentNodeId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)
DELETE FROM umbracoUser2NodePermission WHERE nodeId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)
-- delete the XML nodes...
DELETE FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20
@leekelleher
Copy link
Author

Originally based on a code snippet from a blog post by Lee Messenger.

@engern
Copy link

engern commented Jan 20, 2016

Hi Lee. Found this script today. Do you think it's still valid? I ran it in my dev environment, and added these two lines because of a conflict I got when deleting from umbracoNode:

DELETE FROM UMBRACORELATION WHERE parentid in (select id from umbracoNode WHERE path LIKE '%-20%' AND id != -20)
DELETE FROM UMBRACORELATION WHERE childid in (select id from umbracoNode WHERE path LIKE '%-20%' AND id != -20)

The site seems to run fine after the script...

@tomvanenckevort
Copy link

tomvanenckevort commented Sep 22, 2016

I also had to add the following two statements to make it work:

DELETE FROM cmsTagRelationship WHERE nodeId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)
DELETE FROM umbracoUser2NodeNotify WHERE nodeId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)

(note that this was for a v6.2.4 site)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment