SQL Query Database Size

Transact-SQL (TSQL) Quick Tips – SQL Query Database Size

I recently experienced a situation where disk space was close to capacity.  We manage a lot of databases and wanted to get a quick understanding of which particular databases were taking up the most space.  Using the following query, you can easily view the full list of databases on a specific server, along with the respective database sizes of each.  The query also calculates the database size in Megabytes (MB) and Gigabytes (GB).

The following SQL Statements populate a temp table with information about the size of each database, then the SQL SELECT statement to display the contents of the temp table for review.

 

Results:

SQL Query Database Size

This query utilizes the system stored procedure “sp_databases”, which lists databases that either reside in an instance of the SQL Server or are accessible through a database gateway.

You can modify the query above to suit your needs.

 

Additional Content

Check out more examples by visiting my Home Page

Here you will find topics covering  Qlikview  SQL Server  Excel VBA

 

 

Leave a Comment