Tuesday, October 16, 2012

Finding site column used in content type by querying content db

Exception calling "Delete" with "0" argument(s): "Site columns which are included in content types or on lists cannot be deleted. Please remove all instances of this site column pri
or to deleting it."


ughh..

there are myriad approaches to hunt down that damn column, for example by using powershell. here is an alternative, directly querying the content db


SELECT
     ct.ContentTypeId            [ContentType ID]
,    Definition                  [ContentType Definition]    
,    ct.DeleteTransactionId      [ContentType DeleteTransaction]
,    ctu.ListId                  [List GUID using CT]
,    l.tp_Created                [List Creation Date]
,    tp_DeleteTransactionId      [List DeleteTransaction]
,    tp_FeatureId                [Feature GUID]
FROM
     ContentTypeUsage             ctu
     INNER JOIN dbo.Webs          w  ON ctu.WebId         = w.Id
     INNER JOIN dbo.AllLists      l  ON ctu.ListId        = l.tp_ID
     INNER JOIN dbo.ContentTypes  ct ON ct.ContentTypeId  = ctu.ContentTypeId
WHERE
     ct.Definition LIKE '%your column%'