Thursday, 19 June 2025

DBA- Monitoring Database Size in SQL Server

 


-- Script to monitor database size in SQL Server
SELECT 
name AS DatabaseName,                -- Name of the database
SUM(size) * 8 / 1024 AS SizeInMB,    -- Total size in MB
state_desc AS Status                 -- Current status of the database
FROM sys.master_files
GROUP BY name, state_desc
ORDER BY SizeInMB DESC;                  -- Largest databases first

No comments:

Post a Comment

SQLDBA - Get Space Used by Tables and Indexes in SQL Server

 Get Space Used by Tables and Indexes in SQL Server Databases can consume significant amounts of storage, so it’s important to understand ho...