Preamble

To determine the size of tables in a database hosted on Microsoft SQL Server, you need to perform the following steps:
1. Connect to a database server using SQL Server Management Studio (SSMS)
2. Select a database whose table size you want to define
3. Execute SQL query:
USE {database_name};
GO
SELECT
t.Name AS TableName,
s.Name AS SchemaName,
p.Rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM
sys.tables t
INNER JOIN sys.indexes i ON t.object_id = i.object_id
INNER JOIN sys.partitions p ON i.object_id = p.object_id AND i.index_id = p.index_id
INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id
LEFT OUTER JOIN sys.schemas s ON t.schema_id = s.schema_id
WHERE
t.Name NOT LIKE 'dt%'
AND t.is_ms_shipped = 0
AND i.object_id > 255
GROUP BY
t.Name, s.Name, p.Rows
ORDER BY
t.Name;
GO
where:
- database_name – the name of the database, for which it is necessary to get the list of tables with sizes.
The size of the database tables will be specified by Kilobytes.
If you need to get a limited list of tables, for example, containing certain words in the name, you can shorten the output by adding a condition (t.Name Like ‘%Filter%’) to the WHERE construct
WHERE
t.Name NOT LIKE 'dt%'
AND t.Name Like '%Filter%'
AND t.is_ms_shipped = 0
AND i.object_id > 255
where:
- Filter – is a substring in the table name.
Another way to get the size of tables in the database is to use the built-in stored sp_spaceused procedure.
The stored procedure sp_spaceused outputs the number of rows, disk space reserved and disk space used by the table, indexed view or queue of the Service Broker component in the current database, or outputs disk space reserved and used by the entire database.
The following example provides disk space information for the table_name and its indexes in the database_name database using the stored sp_spaceused procedure:
USE {database_name};
GO
EXEC sp_spaceused N'{dbo}.{table_name}';
GO
The example below shows the disk space for all tables and their indexes in database_name.
USE {database_name};
GO
sp_msforeachtable N'EXEC sp_spaceused [?]';
GO
Determine the disk space used by the indexes
To find out how much space the database table indexes take, you can use the following query:
USE {database_name};
GO
SELECT
OBJECT_NAME(i.object_id) AS TableName,
i.name AS IndexName,
i.index_id AS IndexID,
8 * SUM(a.used_pages) AS 'Indexsize(KB)'
FROM
sys.indexes AS i
JOIN sys.partitions AS p ON p.object_id = i.object_id AND p.index_id = i.index_id
JOIN sys.allocation_units AS a ON a.container_id = p.partition_id
GROUP BY
i.OBJECT_ID, i.index_id, i.name
ORDER BY
OBJECT_NAME(i.object_id),
i.index_id
About Enteros
Enteros offers a patented database performance management SaaS platform. It proactively identifies root causes of complex business-impacting database scalability and performance issues across a growing number of clouds, RDBMS, NoSQL, and machine learning database platforms.
The views expressed on this blog are those of the author and do not necessarily reflect the opinions of Enteros Inc. This blog may contain links to the content of third-party sites. By providing such links, Enteros Inc. does not adopt, guarantee, approve, or endorse the information, views, or products available on such sites.
Are you interested in writing for Enteros’ Blog? Please send us a pitch!
RELATED POSTS
Transforming BFSI Cloud Efficiency: How Enteros Enhances Budgeting and Governance Through the Cloud Center of Excellence
- 13 November 2025
- Database Performance Management
Introduction In the fast-evolving world of Banking, Financial Services, and Insurance (BFSI), cloud transformation has become more than a technological upgrade—it’s a strategic imperative. As financial institutions adopt multi-cloud and hybrid ecosystems, managing cost efficiency, compliance, and performance governance becomes increasingly complex. To meet these challenges, many organizations are establishing Cloud Centers of Excellence (CCoE)—dedicated … Continue reading “Transforming BFSI Cloud Efficiency: How Enteros Enhances Budgeting and Governance Through the Cloud Center of Excellence”
Revolutionizing Healthcare Efficiency: How Enteros Integrates AIOps and Cloud FinOps to Transform Database Performance Management
Introduction In the modern era of digital healthcare, data drives everything—from clinical decision-making and patient outcomes to financial operations and regulatory compliance. As healthcare organizations increasingly adopt cloud technologies, electronic health records (EHRs), and AI-based analytics, the volume and complexity of data have grown exponentially. This digital transformation has brought immense potential for innovation but … Continue reading “Revolutionizing Healthcare Efficiency: How Enteros Integrates AIOps and Cloud FinOps to Transform Database Performance Management”
Maximizing RevOps Efficiency: How Enteros Leverages Generative AI and Cloud FinOps to Redefine Business Performance Optimization
- 12 November 2025
- Database Performance Management
Introduction In today’s fast-paced digital economy, achieving seamless alignment between revenue, operations, and finance has become the ultimate competitive advantage. Businesses are no longer just managing data—they’re orchestrating vast ecosystems of cloud infrastructure, applications, and databases that drive revenue generation and operational agility. However, as organizations scale across multi-cloud environments, the challenge of balancing performance, … Continue reading “Maximizing RevOps Efficiency: How Enteros Leverages Generative AI and Cloud FinOps to Redefine Business Performance Optimization”
Advancing Healthcare Innovation: How Enteros Integrates AIOps and Observability Platforms to Redefine Database Performance Management
Introduction The healthcare industry is undergoing a digital renaissance. From electronic health records (EHR) and telemedicine to AI-powered diagnostics and predictive patient analytics, healthcare systems now depend on massive data ecosystems that must function with precision and reliability. However, as these data systems scale, the complexity of maintaining consistent database performance, cost efficiency, and operational … Continue reading “Advancing Healthcare Innovation: How Enteros Integrates AIOps and Observability Platforms to Redefine Database Performance Management”