Query to Find the Byte Size of Every Table in a Database

Query to Find the Byte Size of Every Table in a Database

This is a quick diagnostic query for finding the byte size of every table in a database when you need to track down what’s actually consuming disk space, before deciding what to archive, compress or partition. Query to Find the Byte Size of Every Table in a Database Use the query below to get the […]

July 18, 2023

This is a quick diagnostic query for finding the byte size of every table in a database when you need to track down what’s actually consuming disk space, before deciding what to archive, compress or partition.

Query to Find the Byte Size of Every Table in a Database

Use the query below to get the byte size of every table in your database, along with a grand total for all tables.

 

SELECT CASE WHEN (GROUPING(sob.name)=1) THEN 'All_Tables'

ELSE ISNULL(sob.name, 'unknown') END AS Table_name,

SUM(sys.length) AS Byte_Length

FROM sysobjects sob, syscolumns sys

WHERE sob.xtype='u' AND sys.id=sob.id

GROUP BY sob.name

WITH CUBE
SQL Server Consulting

Need expert support for SQL Server?

Our senior database team supports SQL Server performance tuning, health checks, migrations, Remote DBA services and urgent operational issues.

Explore Services

SQL Server Consulting

Do You Need Expert Support for Your SQL Server Environment?

Aryasoft’s senior database team provides end-to-end consulting, from SQL Server performance tuning to architecture decisions.

Get SQL Server Support

4.7/5