Skip to content

Instantly share code, notes, and snippets.

@zlypher
Last active September 12, 2018 15:02
Show Gist options
  • Save zlypher/fdb11bdc3e9295fdf813a4c8b9aac5ff to your computer and use it in GitHub Desktop.
Save zlypher/fdb11bdc3e9295fdf813a4c8b9aac5ff to your computer and use it in GitHub Desktop.
Umbraco: Find Document Types
-- Find all umbraco nodes and the document type by the given document type id
-- Replace "XX_DOC_TYPE_ID_XX" with the document type id you want to look for
SELECT
ct.[nodeId] as 'DocumentType ID',
ct.[alias] as 'DocumentType Name',
un.[id] as 'Node ID',
un.[text] as 'Node Name',
un.*
FROM [dbo].[cmsContentType] ct
LEFT JOIN [dbo].[cmsContent] co
ON co.[contentType] = ct.[nodeId]
LEFT JOIN [dbo].[umbracoNode] un
ON un.[id] = co.[nodeId]
WHERE
ct.[nodeId] = XX_DOC_TYPE_ID_XX
-- Find all document types, that are
-- a) unused
-- b) only used on thrashed nodes
SELECT
ct.[nodeId] as 'DocumentType ID',
ct.[alias] as 'DocumentType Name',
un.[id] as 'Node ID',
un.[text] as 'Node Name'
FROM [dbo].[cmsContentType] ct
LEFT JOIN [dbo].[cmsContent] co
ON co.[contentType] = ct.[nodeId]
LEFT JOIN [dbo].[umbracoNode] un
ON un.[id] = co.[nodeId]
WHERE
ct.[nodeId] NOT IN (
SELECT DISTINCT
ct.[nodeId]
FROM [dbo].[cmsContentType] ct
LEFT JOIN [dbo].[cmsContent] co
ON co.[contentType] = ct.[nodeId]
LEFT JOIN [dbo].[umbracoNode] un
ON un.[id] = co.[nodeId]
WHERE
un.[trashed] = 0
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment