uhateoas
10/30/2014 - 9:25 AM

Delete all nodes by a document type in Umbraco

Delete all nodes by a document type in Umbraco

BEGIN TRAN
 
DECLARE @Nodes TABLE (NodeId int)
 
INSERT INTO @Nodes (NodeId)
SELECT top 1000 n.id
FROM cmsContent C 
	INNER JOIN cmsContentType CT ON C.contentType = CT.nodeId 
	INNER JOIN umbracoNode N ON C.nodeId = N.id
WHERE CT.alias = '[Your Document Type Alias Here]'
 
select id, [text] from umbracoNode where id in (select NodeId from @Nodes)
 
delete from cmsPreviewXml where nodeId in (select NodeId from @Nodes)
delete from cmsContentVersion where contentId in (select NodeId from @Nodes)
delete from cmsDocument where nodeId in (select NodeId from @Nodes)
delete from cmsContentXML where nodeId in (select NodeId from @Nodes)
delete from cmsContent where nodeId in (select NodeId from @Nodes)
delete from cmsPropertyData where contentNodeId in (select NodeId from @Nodes)
delete from umbracoRelation where parentId in (select NodeId from @Nodes) OR childId in (select NodeId from @Nodes)
delete from cmsTagRelationship where nodeId in (select NodeId from @Nodes)
delete from umbracoNode where id in (select NodeId from @Nodes)
 
DELETE FROM @Nodes

--COMMIT TRAN 

ROLLBACK TRAN