Vinit Gavankar
Aug 20, 2026
visibility 29
star star star star star
(0 votes)

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');
```
Aug 20, 2026

Comments

Tomas Hensrud Gulla
Tomas Hensrud Gulla Aug 20, 2026 12:49 PM

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/

error Please login to comment.
Latest blogs
Error FK_tblContentSoftlink_tblPropertyDefinition in CMS

Example Error :  Microsoft.Data.SqlClient.SqlException (0x80131904): The DELETE statement conflicted with the REFERENCE constraint "FK_tblContentSo...

Vinit Gavankar | Aug 20, 2026

Optimizely CMP Login Failure After Enabling SSO – The Certificate Mismatch That Locked Everyone Out

Recently, our team faced a production issue where users suddenly lost access to Optimizely CMP, Opti ID Admin Center, and the Optimizely Support...

Madhu | Aug 19, 2026 |

Upgrade Optimizely CMS 12 to .NET 10

If you are still running CMS 12 on .NET 8, it's time to upgrade!

Tomas Hensrud Gulla | Aug 17, 2026 |