How To Check DB Size In SQL Server

Recently, I got the requirement to check the size of my SQL server database. I have identified a few simple and quick approaches to achieve that. In this article, I will guide you through all those approaches to check the size of the DB in an SQL server.

How To Check DB Size In SQL Server

Let us discuss the approaches individually.

Approach-1: Using SQL Server Management Studio (SSMS)

To check DB size in the SQL server, follow the steps below.

1. Log in to the Sql Server Management Studio.

2. Expand the database node, Right-click on the database name, and select the Properties option, as shown in the screenshot below.

how to check the size of db in sql server

3. Click on the General tab to see the Size of the SQL server db under the Database section, as highlighted in the screenshot below.

how to check sql server db size

Approach-2: Using DBCC SQLPERF

Suppose you wish to check all DB size in SQL server. Execute the below query.

DBCC SQLPERF(LOGSPACE);

After executing the above query, I got the expected output below.

How To Check DB Size In SQL Server

Check out How to View SQL Server Error Logs

Approach-3: Using sp_spaceused

If you wish to get the size of a specific database, you can execute the below query.

USE Test;
GO
EXEC sp_spaceused;

After executing the above query, I got the expected output successfully, as shown below.

how to check size of db in sql server

Approach-4: Using sys.database_files

We can also use sys.database_files for this purpose. Execute the below query.

SELECT 
    name AS DatabaseName,
    size/128.0 AS TotalSizeMB
FROM sys.database_files
WHERE type_desc = 'ROWS';

After executing the above query, I got the expected output, as shown in the screenshot below.

how to check all db size in sql server

Conclusion

Knowing the size of your SQL server database is essential if you wish to manage your database effectively. The approaches mentioned above are the ways to achieve this.

You may also like following the articles below.

Top 200 SQL Server Interview Questions and Answers

Free PDF On Top 200 SQL Server Interview Questions And Answers

Download A 40 pages PDF And Learn Now.