Wednesday, November 21, 2018

SQL - List databases, size, and file location

SQL - List databases, size, and file location

This is based on something I found on the internet 7 years ago. Reference unkown

SELECT
    D.name,
    
    F.Name AS FileType,
F.type_desc,
    F.physical_name AS PhysicalFile,
    F.state_desc AS OnlineStatus,
    CAST((F.size*8)/1024 AS VARCHAR(26)) + ' MB' AS FileSize,
    CAST(F.size*8 AS VARCHAR(32)) + ' Bytes' as SizeInBytes
FROM 
    sys.master_files F
    INNER JOIN sys.databases D ON D.database_id = F.database_id
ORDER BY
    D.name

No comments:

Post a Comment