In this blog post, we will see how to check the database size in SQL Server irrespective of Azure and On-Premises using common T-SQL. Here, we will see two easy methods that is Common for both On-Premises and Azure SQL DB.
To Check Current Database Size
Method 1 – Using ‘sys.database_files’ System View
We can use System View named ‘sys.database_files‘ to check current database size like below.
SELECT DB_NAME() AS [database_name], CONCAT(CAST(SUM( CAST( (size * 8.0/1024) AS DECIMAL(15,2) ) ) AS VARCHAR(20)),' MB') AS [database_size] FROM sys.database_files;
Method 2 – Using ‘sp_spaceused’ System Stored Procedure
We can also execute System Stored Procedure named ‘sp_spaceused‘ to check current database size like below. It is the very easy and simplest query to check current database size in SQL Server that works well in both Azure SQL DB and On-Premises.
EXEC sp_spaceused ;
To use it for other databases , simply switch to the relevant database and follow any of the above two methods.
If we want to switch database using Keyboard Shortcut itself simply, check my previous post named – ‘Keyboard Shortcut for Changing Databases/Database Selection in SSMS for both AZURE vs On Premise/Local Server‘.
Thus, in this blog post, we saw two simple methods regarding how to check the database size in SQL Server irrespective of Azure and On-Premises using common T-SQL.