As a database administrator working with SQL Server, I’ve often needed to check the size of tables in my databases. Whether you’re managing the storage or optimizing the performance, knowing how to get table size in SQL Server is an essential skill. In this post, I’ll walk you through various approaches I have identified to retrieve this information, complete with examples and scenarios.
Approach-1 Using SQL Server Management Studio
Follow the below steps.
1. Right-click on the Database name –> Reports –> Standard Reports –> Select Disk Usage by Table option.
Now, you can see the sizes of all the tables from my SQL server database below.
Check out How To Check If Table Exists In SQL Server
Approach-2 Using sp_MSForEachTable
We can execute the query below to get the size of the tables on your SQL server database.
exec sp_MSForEachTable 'exec sp_spaceused [?]';
After executing the above query, I got the expected output, as shown in the screenshot below.
Check out How To Find Column Name In Table SQL Server
Approach-3 Using sp_spaceused
We can also execute the below query, where you need to specify the table name to see the size. Below ProductNew is the name of the table.
exec sp_spaceused [ProductNew]
After executing the above query, I got the expected output below.
Conclusion
Checking the table size is crucial for effective database management. Whether you prefer the GUI approach with SQL Server Management Studio, SQL queries, or check with sp_spaceused
as discussed in this article.
You may also like following the articles below.
- How to copy one table to another in SQL Server
- How To Check If Column Exists In SQL Server Database
- How To Change Column Name In SQL Server
Grey is a highly experienced and certified database expert with over 15 years of hands-on experience in designing, implementing, and managing complex database systems. Currently employed at WEX, USA, Grey has established a reputation as a go-to resource for all things related to database management, particularly in Microsoft SQL Server and Oracle environments. He is a Certified Microsoft SQL Server Professional (MCSE: Data Management and Analytics) and Oracle Certified Professional (OCP), with Extensive database performance tuning and optimization knowledge and a proven track record in designing and implementing high-availability database solutions.