When I right click on Patient Images and click delete I got the following error:
The DELETE statement conflicted with the SAME TABLE REFERENCE constraint "FK_umbracoNode_umbracoNode_id". The conflict occurred in database "VMDent_Live", table "dbo.umbracoNode", column 'parentId'. The statement has been terminated.
I understand why I am getting the error - “Patent Images” is parent of the subnodes, but I have a lot of subnodes and deleting them manually is not an option.
Is there a way to delete the parent folder with all of its subnodes.
Updated code tested with Umbraco 13 if someone needs it.
-- Delete property data
DELETE FROM umbracoPropertyData
WHERE versionId IN (
SELECT id FROM umbracoContentVersion
WHERE nodeId IN (SELECT id FROM @NodesToDelete)
);
-- Delete document versions
DELETE FROM umbracoDocumentVersion
WHERE id IN (
SELECT id FROM umbracoContentVersion
WHERE nodeId IN (SELECT id FROM @NodesToDelete)
);
-- Delete content versions
DELETE FROM umbracoContentVersion
WHERE nodeId IN (SELECT id FROM @NodesToDelete);
-- Delete documents
DELETE FROM umbracoDocument
WHERE nodeId IN (SELECT id FROM @NodesToDelete);
-- Delete content
DELETE FROM umbracoContent
WHERE nodeId IN (SELECT id FROM @NodesToDelete);
-- Delete redirects
DELETE FROM umbracoRedirectUrl
WHERE contentKey IN (SELECT uniqueId FROM umbracoNode WHERE id IN (SELECT id FROM @NodesToDelete));
-- Delete relations (both parent & child)
DELETE FROM umbracoRelation
WHERE parentId IN (SELECT id FROM @NodesToDelete)
OR childId IN (SELECT id FROM @NodesToDelete);
-- Finally, delete the nodes
DELETE FROM umbracoNode WHERE id IN (SELECT id FROM @NodesToDelete);