How to use the sp_spaceused Stored Procedure In SQL
Another way to get the size of a database in SQL Server is to use the sp_spaceused system stored procedure路 This stored procedure displays the number of rows, disk space reserved, and disk space used by a table, indexed view, or Service Broker queue in the current database, or displays the disk space reserved and used by the whole database路
To use it, we simply switch to the relevant database and execute the procedure.
USE tempdb; EXEC sp_spaceused;
Output:
sp_spaceused Stored Procedure:
Explanation: This will return two result sets that provide the relevant information. The first result set shows the name, the size, and the unallocated space of the database. The second result set shows the reserved space, the data space, the index space, and the unused space of the database.
How to Get Database Size in SQL
SQL database size is vital for effective management. It indicates the storage space occupied by tables, indexes, and other components. Knowing the size of a database is useful for various purposes, such as monitoring the growth, estimating the backup time, planning the storage capacity, and optimizing performance路
In this article, we will learn how to get the size of a database in SQL Server using different queries or management tools.