How to use Stored Proc sp_spaceused In SQL
SQL Server has a sp_spaceused stored procedure that, when executed, produces tables then defining the current space used for a certain database or any object within that database. This stored procedure provides data about data size, unallocated space, reserved space, data space, index space and space across unused.
To use sp_spaceused, execute the following SQL command:
USE [YourDatabaseName];
GO
EXEC sp_spaceused;
OUTPUT:
Database_name |
Database_size |
Unallocated space |
Reserved |
Data |
Index_size |
Unused |
---|---|---|---|---|---|---|
YourDatabase |
10240 KB |
512 KB |
5120 KB |
4096 KB |
1024 KB |
0 KB |
Explanation: The result set from sp_spaceused includes the following columns:
- Database_name: Name of the database.
- Database_size: Total size of the database.
- Unallocated space: Space available for new data.
- Reserved: Total reserved space for database objects.
- Data: Used space by data.
- Index_size: Used space by indexes.
- Unused: Space that is allocated but not used.
How to Get SQL Server Database Size
The ability to keep track of our SQL Server databases is very important to maintaining our storage resources effectively and within the proper performance limits. Knowing how large databases are can put us in a position to set up storage capacity which indicates the beginning of solving issues related to disk space, and improving database performance.
In this article, We will learn about how to Get SQL Server Database Size by understanding various methods along with the implementation and so on.