Tuesday, March 14, 2023

Get SQL Server Database Size, Location for all Databases

Here are the SQL Server queries to get all SQL Server database data file and log file Size, Location:

 SELECT DB_NAME(database_id) AS [Database Name],

       Name AS [Logical Name],
       Physical_Name AS [Physical Name],
       (size*8)/1024 AS [Size - MB]
 FROM sys.master_files WHERE database_id > 4


If you want to combine Data File & Log File Size:

SELECT DB_NAME(database_id) AS [Database Name],
       SUM((size*8)/1024) [Size - MB]
FROM sys.master_files
WHERE database_id > 4
group by DB_NAME(database_id)
order by DB_NAME(database_id)

This will give you all Databases attached to a specific instance, excluding SQL Server system Databases like Master, Model, etc. (So we’ve: WHERE database_id > 4)

Source: https://www.sharepointdiary.com/2013/03/get-sql-server-database-size-location.html

No comments:

Post a Comment

Cuando el código funciona, pero no tiene tests: ¿y ahora qué?

Seguramente te ha pasado alguna vez. Te dan acceso al repositorio de un nuevo proyecto. Lo abres con curiosidad, esperas encontrar una estru...