Template Usage - Sitecore

Overview

This article describes a way to query your Sitecore database to determine where a template is used. These solutions may require the dbo.ItemTree view, available here.

Templates Used by a Template

declare
     @myTemplateID uniqueidentifier = 'CCB6DC31-DB14-47E3-902D-55B2C0767A71'
    
select 
    t.*
    
from 
    dbo.Fields f
    
    inner join dbo.ItemTree t
        on f.ItemId = t.ID
        
where 1=1
    and FieldId = '12C33F3F-86C5-43A5-AEB4-5598CEC45116'
    and Value like '%' + CONVERT(varchar(100), @myTemplateID) + '%'

Templates Used by a Site

select distinct 
    b.ItemPath
from 
    dbo.ItemTree a
    
    inner join dbo.ItemTree b
        on a.TemplateID = b.ID
where 1=1
    and a.ItemPath like '/sitecore/content/MySite%'
order by
    b.ItemPath