Now, we are going to retrive the file details from AllDocs Database. Which has the informations about the files stored in SharePoint List or Library.

— Returns all document from all lists availabe in WebApplication
SELECT AllDocs.Leafname AS FileName’
                 AllDOcs.Dirname AS ‘Folder Path’
                 AllLists.tp_Title AS ‘List Title’,
                 Webs.Title AS ‘Web Title’
FROM AllDocs
JOIN AllLists
ON
AllLists.tp_Id=AllDocs.ListId
JOIN Webs
ON
Webs.Id=AllLists.tp_WebId
ORDER BY
webs.title

If you need the file informations about particular document type. Use the Extension column to check the document type.

For Ex., The following Query returns only master pages on all WebSites,

— Returns master pages in WebApplication for all WebSites
SELECT AllDocs.Leafname AS FileName’
                 AllDocs.Dirname AS ‘Folder Path’
                 AllLists.tp_Title AS ‘List Title’,
                 Webs.Title AS ‘Web Title’
FROM AllDocs
JOIN AllLists
ON
AllLists.tp_Id=AllDocs.ListId
JOIN Webs
ON
Webs.Id=AllLists.tp_WebId
WHERE Extension=’master’
ORDER BY Webs.Title

Like the above query, we can get all type of documents.