Technical Article

Database mdf & ldf files size, used space, Free space in MB

,

Below script will help to get the Database mdf & ldf files size, used space, Free space in MB.

If we have free space in the file then will shrink to reclaim the space.

I used the same script in one of my environment to get details for used and free space in the file.

If huge free space in master datafile then shrink the file and run rebuild index.

Note: It should be done in non business hours only.

 

  1. Open SSMS
  2. Connect SQL server
  3. Run the below query
Use DB_Name-- Mention database name to get the details 
go

select
name
, filename,
(growth/1024) as Growth_MB
, convert(decimal(12,3),round(sf.size/128.00,2)) as FileSize_MB
, convert(decimal(12,3),round(fileproperty(sf.name,'SpaceUsed')/128.00,2)) as SpaceUsed_MB
, convert(decimal(12,3),round((sf.size-fileproperty(sf.name,'SpaceUsed'))/128.00,2)) as FreeSpace_MB
from dbo.sysfiles sf

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating