Alternatives · Basic Logics · Keyboard Shortcuts · Real Scenario Logic's

Check Database Size in SQL Server for both Azure and On-Premises

Introduction

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 ;

NOTE-

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‘.

Conclusion

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.

Thanks for reading!

FOLLOW BLOG for interesting upcoming posts!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s