Skip to content

Instantly share code, notes, and snippets.

@craigtp
Last active November 16, 2023 15:41
Show Gist options
  • Save craigtp/3237124 to your computer and use it in GitHub Desktop.
Save craigtp/3237124 to your computer and use it in GitHub Desktop.
List the largest databases on a SQL Server instance
SELECT DB_NAME(database_id) AS DatabaseName,
Name AS Logical_Name,
Physical_Name, (size*8)/1024 SizeMB
FROM sys.master_files
ORDER BY SizeMB DESC
@gpicorelli
Copy link

Doesn't work. Whatever's inside your 'database_id', it says "Invalid column name". Also it's unclear what Name is?

Completing the table name with database name "master" in the FROM clause avoids this
This code runs independently of the selected database

SELECT DB_NAME(database_id) AS DatabaseName,
Name AS Logical_Name,
Physical_Name, ((size/(1024/8))/1000) SizeGB
FROM master.sys.master_files
ORDER BY SizeGB DESC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment