Get count of pages, blocks , Assets from the CMS.
The following queries retrieve details from the CMS database. Make sure to try these queries locally first.
Step 1 — Discover your content type bases first:
```
SELECT Base, COUNT(*) AS TypeCount
FROM tblContentType
GROUP BY Base
ORDER BY TypeCount DESC;
```
Step 2 — Count all content grouped by base type (single query):
```
SELECT
ct.Base AS ContentBase,
ct.Name AS ContentTypeName,
COUNT(c.pkID) AS ContentCount
FROM tblContent c
INNER JOIN tblContentType ct ON c.fkContentTypeID = ct.pkID
GROUP BY ct.Base, ct.Name
ORDER BY ct.Base, ContentCount DESC;
```
Step 3 — Individual counts per category:
```
-- Pages
SELECT COUNT(*) AS PageCount
FROM tblContent c
INNER JOIN tblContentType ct ON c.fkContentTypeID = ct.pkID
WHERE ct.Base = 'Page';
-- Blocks
SELECT COUNT(*) AS BlockCount
FROM tblContent c
INNER JOIN tblContentType ct ON c.fkContentTypeID = ct.pkID
WHERE ct.Base = 'Block';
-- Images (adjust base value based on Step 1 results)
SELECT COUNT(*) AS ImageCount
FROM tblContent c
INNER JOIN tblContentType ct ON c.fkContentTypeID = ct.pkID
WHERE ct.Base = 'Image';
-- Documents / Files
SELECT COUNT(*) AS DocumentCount
FROM tblContent c
INNER JOIN tblContentType ct ON c.fkContentTypeID = ct.pkID
WHERE ct.Base IN ('File', 'Video', 'Media');
```
Nice queries!
And if you can't access the database directly, this addon can help:
https://www.gulla.net/no/blog/sql-addon-for-optimizely-cms-12-updated-with-new-features/