Skip to content

Instantly share code, notes, and snippets.

@kipusoep
Created December 20, 2016 12:25
Show Gist options
  • Save kipusoep/bf5bde5ed85a896afda25df6b465ce76 to your computer and use it in GitHub Desktop.
Save kipusoep/bf5bde5ed85a896afda25df6b465ce76 to your computer and use it in GitHub Desktop.
--deletes in Document
--at this point all associated media files are deleted
delete from umbracoDomains where id 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);
--deletes in Content
delete from cmsPropertyData where contentNodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);
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 cmsContentXml where NodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);
--deletes in CMSNode
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);
delete from cmsTask 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);
delete from cmsTagRelationship where nodeId 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 from cmsContent where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);
delete from umbracoNode where path like '%-20%' and id!=-20;
@Nicholas-Westby
Copy link

Seems like the umbracoUser2NodePermission table got renamed in a recent Umbraco version, so line 18 should now be:

DELETE FROM umbracoUserGroup2NodePermission WHERE nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);

See here: https://our.umbraco.com/forum/using-umbraco-and-getting-started/87181-unable-to-empty-recycle-bin#comment-300165

@NurhakKaya
Copy link

I can confirm this script, together with Nicholas's addition, is valid for Umbraco version 7.15.4 assembly: 1.0.7381.11453.

@mistyn8
Copy link

mistyn8 commented Jan 6, 2021

I have a couple of issues..
When I get to delete from umbracoNode where path like '%-20%' and id!=-20;
when there are nodes in the recycle bin with access restrictions the FK constraints on nodeId, loginNodeId and noAccessNodeId prevent deletes.
I also get an error about parentId on node SameTable constraint stops delete ??

Any work around?

@PanktiBodiwala
Copy link

PanktiBodiwala commented Jul 1, 2021

Please try the following scripts if you haven't found the work around yet, works well with v8.13.1

--deletes in Document
--at this point all associated media files are deleted
delete from umbracoDomain where id in (select id from umbracoNode where path like '%-20%' and id!=-20);
delete from umbracoDocument where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);

--deletes in Content
delete from umbracoPropertyData where versionId in (select id from umbracoContentVersion where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20));
delete from umbracoDocumentVersion where id in (select id from umbracoContentVersion where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20));
delete from umbracoContentVersion where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);
delete from cmsContentNu where NodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);

--deletes in CMSNode
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);
delete from umbracoUser2NodeNotify where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);
delete from cmsTagRelationship where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);
delete from umbracoUserGroup2NodePermission where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);
delete from umbracoContent where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);
delete from umbracoContentSchedule where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20)
delete from umbracoRedirectUrl where contentKey in (select uniqueId from umbracoNode where path like '%-20%' and id!=-20)
delete from umbracoNode where path like '%-20%' and id!=-20;

@amitch17
Copy link

Updated for Umbraco 11.4.2 (to include VersionCulture tables):


--deletes in Document
--at this point all associated media files are deleted
delete from umbracoDomain where id in (select id from umbracoNode where path like '%-20%' and id!=-20);
delete from umbracoDocument where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);
delete from umbracoDocumentVersion where id in (select id from umbracoContentVersion where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20));
delete from umbracoDocumentCultureVariation where nodeid in (select id from umbracoNode where path like '%-20%' and id!=-20);

--deletes in Content
delete from umbracoPropertyData where versionId in (select id from umbracoContentVersion where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20));
delete from umbracoContentVersionCultureVariation where versionid in (select id from umbracoContentVersion where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20));
delete from umbracoContentVersion where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);
delete from cmsContentNu where NodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);

--deletes in CMSNode
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);
delete from umbracoUser2NodeNotify where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);
delete from cmsTagRelationship where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);
delete from umbracoUserGroup2NodePermission where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);
delete from umbracoContent where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20);
delete from umbracoContentSchedule where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20)
delete from umbracoRedirectUrl where contentKey in (select uniqueId from umbracoNode where path like '%-20%' and id!=-20)
delete from umbracoNode where path like '%-20%' and id!=-20;

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