Get the size of SQL Server Database and Tables

In this tutorial you will learn how to get the size of SQL Server database and its tables. It is a good approach to check the size of your database routine wise and then performed appropriate action with respect to analysis. In the following example we will find the size of a table.

Get the size of SQL Server Database and Tables

Getting the size of table

Syntax

EXEC SP_SPACEUSED 'YOUR TABLE NAME'


MS SQL Server contains a built-in system store procedure named SP_SPACEUSED. This store procedure is very handy. Using this store procedure you can find the size of the database as well as the size of the any table you want. When you execute the SP_SPACEUSED with table name as a parameter then it will provide you following information of that table.


1) name
2) rows
3) reserved
4) data
5) index_size
6) unused


The following example shows how to get the size of all tables from database


EXEC sp_MSforeachtable @command1="EXEC sp_spaceused '?'"



Getting the size of ms sql server database


To find the size of ms sql server database, you have to execute the SP_SPACEUSED store procedure without any parameter. It will automatically provides you the size of the database that you will be using.


Syntax


EXEC SP_SPACEUSED


I love your feedback

0 comments: